Add header to response before response is cached

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Add header to response before response is cached

Roger Fischer
Hello,

is there a way in an NGINX HTTP Proxy to add a header to the response before it is cached?

I would like to capture some information from the request and add it to the cached response, so that all clients getting the cached response receive that info.

Thanks…

Roger

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Add header to response before response is cached

Francis Daly
On Mon, Oct 07, 2019 at 12:07:29PM -0700, Roger Fischer wrote:

Hi there,

> is there a way in an NGINX HTTP Proxy to add a header to the response before it is cached?
>
> I would like to capture some information from the request and add it to the cached response, so that all clients getting the cached response receive that info.

If you do not find a more direct way (either by config or by coding),
then you could potentially add a new nginx server{} to modify the upstream
response as you want.

That is:

* main nginx does proxy_pass to new nginx, including your extra
information as proxy_set_header values. main nginx does proxy_cache
the response.

* new nginx does proxy_pass to upstream; does not proxy_cache the response;
and does add_header with your extra information so that that extra
information is in the response that goes to main nginx.

"new nginx" can be a server{} that listens on a loopback port, or on a
unix domain socket -- something that the world does not need to access
directly.

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx