Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request help: The proxy-cache plugin overrides Cache-Control in upstream header. #3373

Closed
myWsq opened this issue Jan 21, 2021 · 1 comment · Fixed by #3789
Closed

request help: The proxy-cache plugin overrides Cache-Control in upstream header. #3373

myWsq opened this issue Jan 21, 2021 · 1 comment · Fixed by #3789
Labels
good first issue Good for newcomers

Comments

@myWsq
Copy link

myWsq commented Jan 21, 2021

Issue description

The proxy cache plugin overrides the Cache Control in the upstream header, even if the plugin is not used in the route.

{% if enabled_plugins["proxy-cache"] then %}
### the following configuration is to cache response content from upstream server
set $upstream_cache_zone off;
set $upstream_cache_key '';
set $upstream_cache_bypass '';
set $upstream_no_cache '';
set $upstream_hdr_expires '';
set $upstream_hdr_cache_control '';
proxy_cache $upstream_cache_zone;
proxy_cache_valid any {% if proxy_cache.cache_ttl then %} {* proxy_cache.cache_ttl *} {% else %} 10s {% end %};
proxy_cache_min_uses 1;
proxy_cache_methods GET HEAD;
proxy_cache_lock_timeout 5s;
proxy_cache_use_stale off;
proxy_cache_key $upstream_cache_key;
proxy_no_cache $upstream_no_cache;
proxy_cache_bypass $upstream_cache_bypass;
proxy_hide_header Cache-Control;
proxy_hide_header Expires;
add_header Cache-Control $upstream_hdr_cache_control;
add_header Expires $upstream_hdr_expires;
add_header Apisix-Cache-Status $upstream_cache_status always;
{% end %}

Disabling the plugin in config.yml solves this problem, but some routes need to enable the plugin. How should I preserve the Cache Control in the upstream header with the proxy cache plugin globally enabled?

Environment

@spacewander
Copy link
Member

             proxy_hide_header                   Cache-Control; 
             proxy_hide_header                   Expires; 
             add_header      Cache-Control       $upstream_hdr_cache_control; 
             add_header      Expires             $upstream_hdr_expires; 
             add_header      Apisix-Cache-Status $upstream_cache_status always; 

We can remove them from the Nginx conf, and implement them in

function _M.header_filter(conf, ctx)

PR is welcome!

@spacewander spacewander added the good first issue Good for newcomers label Jan 22, 2021
spacewander added a commit to spacewander/incubator-apisix that referenced this issue Mar 9, 2021
Fix apache#3373
Fix apache#3677

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants