I'm building "my first reverse proxy" and I think I had the idea wrong. Instead of mirroring modified requests back, what it really should be doing is forwarding the initial http call to another destination, and taking headers and putting them in response to the client - not mirroring the clients headers back.
On Monday, September 4, 2017 at 5:11:04 PM UTC+2, rpaprocki wrote:
Hi,
Likely you are sending back hop-by-hop headers that are interfering with the client's understanding of the response (e.g., Content-Length).
For this kind of mirror it's better to send the request headers in the response body, rather than back as request headers. Have a look at something like
httpbin.org for an example.
Sent from my iPhone
What would be the correct way to mirror all headers from the request out to the response?
As soon as I introduce a for loop in here, Postman hangs on the response, and it's a bit hard to debug. Setting headers individually seems to work fine:
location / {
default_type text/html;
client_max_body_size 512k;
client_body_buffer_size 512k;
header_filter_by_lua_block {
-- mirror headers sent in to output
local h = ngx.req.get_headers()
for k, v in pairs(h) do
ngx.header[k] = v
end
}
content_by_lua_file lua/fix_response.lua;
}
.