save parent request's headers before do subrequest, after subrequest done recover the heades use saved headers. like this:
```lua
local old_headers = ngx.req.get_headers()
for k,v in pairs(old_headers) do
ngx.req.clear_header(k)
end
ngx.req.set_header("new_header", "added_header")
local resp = ngx.location.capture_multi({
{"/xxx", method=ngx.HTTP_GET}
})
for k,v in pairs(old_headers) do
ngx.req.set_header(k, v)
end
```
At 2019-06-19 15:15:06, "tweyseo" <twe...@gmail.com> wrote:
i don't want inherit headers from original request and use new headers in subrequest.
在 2019年6月19日星期三 UTC+8下午2:59:59,juzi写道:
when you use `capture`, you can add header in subrequest.
At 2019-06-18 23:41:26, "tweyseo" <twe...@gmail.com> wrote:
Although original request headers could be ignored by setting proxy_pass_request_headers
to off
in subrequest locations, but i can only add my own headers in the subrequest by setting proxy_set_header
until i used balancer_by_lua*
directive. I thought i could add my own headers before set_current_peer
,but unfortunately, the setting of proxy_pass_request_headers
take effect only after balancer_by_lua*
directive.
So is there any other suggestions about adding my own headers in the subrequest that generated via capture
?
.
tweyseo
I've done this before, but the thing is this solution relies heavily on business logic (the time to recover the origin headers)
在 2019年6月19日星期三 UTC+8下午5:17:13,juzi写道:
save parent request's headers before do subrequest, after subrequest done recover the heades use saved headers. like this:
```lua
local old_headers = ngx.req.get_headers()
for k,v in pairs(old_headers) do
ngx.req.clear_header(k)
end
ngx.req.set_header("new_header", "added_header")
local resp = ngx.location.capture_multi({
{"/xxx", method=ngx.HTTP_GET}
})
for k,v in pairs(old_headers) do
ngx.req.set_header(k, v)
end
```
At 2019-06-19 15:15:06, "tweyseo" <twe...@gmail.com> wrote:
i don't want inherit headers from original request and use new headers in subrequest.
在 2019年6月19日星期三 UTC+8下午2:59:59,juzi写道:
when you use `capture`, you can add header in subrequest.
At 2019-06-18 23:41:26, "tweyseo" <twe...@gmail.com> wrote:
Although original request headers could be ignored by setting proxy_pass_request_headers
to off
in subrequest locations, but i can only add my own headers in the subrequest by setting proxy_set_header
until i used balancer_by_lua*
directive. I thought i could add my own headers before set_current_peer
,but unfortunately, the setting of proxy_pass_request_headers
take effect only after balancer_by_lua*
directive.
So is there any other suggestions about adding my own headers in the subrequest that generated via capture
?
.