title: Nginx access_by_lua_block not executed in case of 3XX redirects
body: <p>I am using the <code>access_by_lua_block</code> in my nginx configuration to add/modify custom request headers (let's say <code>ngx.req.set_header("foo", "bar")</code>). I am accessing these headers within the <code>header_filter_by_lua_block</code> as <code>ngx.var["http_foo"]</code> just before returning any response to the client.
  This works fine in case of passing the request to upstream, however it doesn't work in case of redirects.
  So basically,</p>
  
  <p>This works (No redirect).</p>
  
  <pre><code>location /abc {
     proxy_pass some_upstream;
  
     access_by_lua_block {
        ngx.req.set_header("foo", "bar")
     }
  
     header_filter_by_lua_block {
       ngx.header["foo2"] = ngx.var["http_foo"] # this is correctly getting the value of "foo" header set above
     }
  }
  </code></pre>
  
  <p>This doesn't work (With Redirect)</p>
  
  <pre><code>location /abc {
     access_by_lua_block {
        ngx.req.set_header("foo", "bar")
     }
  
     header_filter_by_lua_block {
       ngx.header["foo2"] = ngx.var["http_foo"] # this is not getting the value of "foo" header set above
     }
  
     return 301 xyz.com;
  }
  </code></pre>
  
  <p>The access_by_lua_block is not getting executed in case of redirects only (return 301 statement). I don't understand why so? Because access_by_lua_block has a execution priority before the content phase (<a href="https://openresty-reference.readthedocs.io/en/latest/Directives/" rel="nofollow noreferrer">link</a>)</p>