srcache_store_pass_header
The `srcache_store_pass_header` directive specifies which HTTP headers should be passed from the upstream response to the stored cache entry without modification.
Description
The srcache_store_pass_header directive is part of the ngx_srcache module, which allows NGINX to perform transparent subrequest-based caching. This directive is specifically used for controlling which headers in the upstream response should be retained and passed through when the cache is storing responses. By default, NGINX is configured to hide certain headers that are typically irrelevant or sensitive, such as Set-Cookie or Connection. However, using the srcache_store_pass_header, administrators can specify individual headers that they want to retain in the cache, ensuring that subsequent clients can obtain these headers when served from the cache.
The syntax for this directive allows it to accept one or more header names as arguments. For instance, if you want to pass the X-My-Custom-Header from the upstream response into the cache, you would set it like this: srcache_store_pass_header X-My-Custom-Header;. This can be particularly useful for scenarios where certain headers are critical for the application logic or client handling and should not be filtered out.
When the specified headers are present in the response from the upstream server, they will be included in the cached response for future requests, allowing clients to access these directly, instead of them being stripped off during the caching process. Care should be taken since passing sensitive information in headers can lead to security vulnerabilities if not managed correctly.
Config Example
location /example {
srcache_store_pass_header X-My-Custom-Header;
srcache_store my_cache;
}Be cautious of passing headers that may expose sensitive information.
Ensure that the headers you pass are necessary for application functionality, to avoid unnecessary overhead.
Multiple headers can be specified, but they need to be listed separately. For example: srcache_store_pass_header X-Header1; srcache_store_pass_header X-Header2;