openresty / headers-more-nginx-module

Set, add, and clear arbitrary output headers in NGINX http servers
1.65k stars 221 forks source link

more_set_input_headers not adding new headers on subrequest #142

Closed psykro closed 2 years ago

psykro commented 2 years ago

Hello,

I wrote a similar (but extremely limited) module to add input headers to my subrequests. While i can update existing one, the new one are just ignored.

Therefore I tested your module and i face the same issue, new headers are not added. Although it is stated in readme that it works with subrequests.

I tested also with lua and same issue.

Here is my location configuration (cleaned up :)):

   location ~/location/origin/(.*) {
      rewrite_by_lua_block {
          ngx.req.set_header("User-Agent233", "zzzzz")
      }
      more_set_input_headers               "BIGHEADER: test";
      proxy_pass                      http://$upstream/$1$is_args$args;
   }

Neither User-Agent233 nor BIGHEADER are added

To give a bit more context, i initiate subrequests from inside another module. Those subrequest goes to a location, which in turns proxy_pass to an external server. I keep the body response from the subrequest.

Do you have any idea what could be wrong with my subrequests ? Since you write this also work with subrequests, i belive this is the subrequest initialization which is wrong

psykro commented 2 years ago

For your information, i managed to make it work with my subrequests.

Seems related to issue #19, in my module I duplicated the headers_in list fom the parent request before adding my new headers. And TADA! my new headers got inserted. I got inspiration from openresty code

Also, after doing this, now headers are also added with more_set_input_headers and LUA. The above configuration now works.

Closing the issue, probably the fix would be to duplicate the parent headers in more_set_input_headers.