Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Rewrite: Ignore headers if we have proxy_cache_valid set. #92

Merged
merged 3 commits into from
Aug 21, 2014

Conversation

jagtalon
Copy link
Member

We don't want response headers from the endpoints from interfering with proxy_cache_valid. Using proxy_ignore_headers will fix that. We only ignore the headers if we explicitly want to set the caching.

From the proxy_cache_valid documentation:

Parameters of caching can also be set directly in the response header. This has higher priority than setting of caching time using the directive. The “X-Accel-Expires” header field sets caching time of a response in seconds. The zero value disables caching for a response. If the value starts with the @ prefix, it sets an absolute time in seconds since Epoch, up to which the response may be cached. If the header does not include the “X-Accel-Expires” field, parameters of caching may be set in the header fields “Expires” or “Cache-Control”. If the header includes the “Set-Cookie” field, such a response will not be cached. Processing of one or more of these response header fields can be disabled using the proxy_ignore_headers directive.

And from the proxy_ignore_headers documentation:

"X-Accel-Expires”, “Expires”, “Cache-Control”, and “Set-Cookie” set the parameters of response caching;

Here it is caching things that should be cached (see X-Cache-Status header):
21

22

Ones that shouldn't be cached still aren't cached like Dictionary/Audio:
23

We don't want response headers from the endpoints from interfering with proxy_cache_valid. Using proxy_ignore_headers will fix that.

From the proxy_cache_valid documentation:
> Parameters of caching can also be set directly in the response header. This has higher priority than setting of caching time using the directive. The “X-Accel-Expires” header field sets caching time of a response in seconds. The zero value disables caching for a response. If the value starts with the @ prefix, it sets an absolute time in seconds since Epoch, up to which the response may be cached. If the header does not include the “X-Accel-Expires” field, parameters of caching may be set in the header fields “Expires” or “Cache-Control”. If the header includes the “Set-Cookie” field, such a response will not be cached. Processing of one or more of these response header fields can be disabled using the proxy_ignore_headers directive.
@@ -159,7 +159,12 @@ sub _build_nginx_conf {
$cfg .= "\trewrite ^".$self->path.($self->has_from ? $self->from : "(.*)")." ".$uri_path." break;\n";
$cfg .= "\tproxy_pass ".$scheme."://".$host.":".$port."/;\n";
$cfg .= "\tproxy_set_header ".$self->proxy_x_forwarded_for.";\n" if $is_duckduckgo;
$cfg .= "\tproxy_cache_valid ".$self->proxy_cache_valid.";\n" if $self->has_proxy_cache_valid;

if($self->proxy_cache_valid) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should call the predicate function via $self->has_proxy_cache_valid.

@jagtalon
Copy link
Member Author

@nilnilnil Ah, you're right. Good catch! Changed it to the predicate function.

@nilnilnil
Copy link
Contributor

👍 thx

nilnilnil added a commit that referenced this pull request Aug 21, 2014
Rewrite: Ignore headers if we have proxy_cache_valid set.
@nilnilnil nilnilnil merged commit c14bc6e into master Aug 21, 2014
@nilnilnil nilnilnil deleted the jag/ignore-headers branch August 21, 2014 18:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants