Skip to content

Commit ec2e133

Browse files
committed
Fix runtime refresh purge entry regressions
1 parent bc21f48 commit ec2e133

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

ngx_cache_purge_module.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ static size_t ngx_http_cache_purge_content_type_text_size =
8383
static const char ngx_http_cache_purge_body_templ_json[] =
8484
"{\"Key\": \"%s\", \"Status\": \"%s\"}";
8585
static const char ngx_http_cache_purge_body_templ_html[] =
86-
"<html><head><title>Cache Purge</title></head>"
87-
"<body bgcolor=\"white\"><center><h1>Cache Purge</h1>"
86+
"<html><head><title>Successful purge</title></head>"
87+
"<body bgcolor=\"white\"><center><h1>Successful purge</h1>"
8888
"<p>Key: %s</p><p>Status: %s</p></center></body></html>";
8989
static const char ngx_http_cache_purge_body_templ_xml[] =
9090
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
@@ -2088,6 +2088,19 @@ ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r) {
20882088
}
20892089

20902090
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
2091+
2092+
/*
2093+
* Runtime refresh on a purge entry still needs a real proxy_cache
2094+
* definition in the current location so cache_zone/cache_key can be
2095+
* evaluated safely. A plain /purge endpoint with only proxy_pass and
2096+
* proxy_cache_purge cannot be auto-upgraded into refresh.
2097+
*/
2098+
if (refresh && !plcf->upstream.cache) {
2099+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2100+
"runtime refresh rejected: current location has no proxy_cache configuration");
2101+
return NGX_HTTP_BAD_REQUEST;
2102+
}
2103+
20912104
r->upstream->conf = &plcf->upstream;
20922105

20932106
# if (nginx_version >= 1007009)
@@ -2120,7 +2133,7 @@ ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r) {
21202133
return ngx_http_cache_purge_send_capability_error(r, refresh);
21212134
}
21222135

2123-
if (cplcf->conf->refresh) {
2136+
if (refresh) {
21242137
return ngx_http_cache_purge_refresh(r, cache);
21252138
}
21262139

0 commit comments

Comments
 (0)