ShiningRush commented on a change in pull request #2271:
URL: https://github.com/apache/apisix/pull/2271#discussion_r495516479



##########
File path: apisix/core/response.lua
##########
@@ -97,19 +103,43 @@ function _M.set_header(...)
             error("should be a table if only one argument", 2)
         end
 
-        for k, v in pairs(headers) do
-            ngx_header[k] = v
+        if append then
+            for k, v in pairs(headers) do
+                ngx_add_header(k, v)
+            end
+
+        else
+            for k, v in pairs(headers) do
+                ngx_header[k] = v
+            end

Review comment:
       In theory, the comparison of boolean values ​​will not cause significant 
performance loss, but I have not verified this in Lua.
   We can get two benefits by extracting the `for`:
   -Better readability: less code.
   -Better scalability: If there are other conditional parameters to be added 
in the future, the amount of modified code is less
   
   It was mentioned in 
[Refactoring](https://martinfowler.com/books/refactoring.html) that we should 
give priority to readability and wait until performance bottlenecks occur 
before targeted optimization.
   However, we can also keep the existing code and modify it until the next 
modification, in exchange for a slight performance improvement.
   @membphis @spacewander How dow you think?




----------------------------------------------------------------
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.

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


Reply via email to