spacewander commented on code in PR #8824:
URL: https://github.com/apache/apisix/pull/8824#discussion_r1118203356


##########
apisix/core/request.lua:
##########
@@ -131,26 +129,41 @@ function _M.set_header(ctx, header_name, header_value)
         changed = a6_request.is_request_header_set()
     end
 
-    ngx.req.set_header(header_name, header_value)
+    update_func(header_name, header_value)
 
     if is_apisix_or and not changed then
         -- if the headers are not changed before,
         -- we can only update part of the cache instead of invalidating the 
whole
         a6_request.clear_request_header()
         if ctx and ctx.headers then
-            ctx.headers[header_name] = header_value
+            if override or not ctx.headers[header_name] then
+                ctx.headers[header_name] = header_value
+            else
+                local values = ctx.headers[header_name]
+                if type(values) == "table" then
+                    table_insert(values, header_value)
+                else
+                    ctx.headers[header_name] = {values, header_value}
+                end
+            end
         end
     end
 end
 
-function _M.add_header(header_name, header_value)
-    local err
-    header_name, err = _validate_header_name(header_name)
-    if err then
-        error(err)
+function _M.set_header(ctx, header_name, header_value)
+    if type(ctx) == "string" then
+        log.warn("DEPRECATED: use set_header(ctx, header_name, header_value) 
instead")

Review Comment:
   We can move the DEPRECATED log into the common function, and show a 
different log according to the override parameter.



##########
apisix/core/request.lua:
##########
@@ -131,26 +129,41 @@ function _M.set_header(ctx, header_name, header_value)
         changed = a6_request.is_request_header_set()
     end
 
-    ngx.req.set_header(header_name, header_value)
+    update_func(header_name, header_value)

Review Comment:
   We can use override instead of passing an extra function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to