Skip to content

Commit 0360117

Browse files
authored
Merge pull request #11 from torden/dev/change-decline-response
fixed wrong comment in README.md, change response at error (404 to 412)
2 parents 19348b7 + 3a8c08a commit 0360117

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,20 @@ Sample configuration (Optional)
177177

178178
cache_purge_response_type json;
179179

180-
location / { //json
180+
location / { #json
181181
proxy_pass http://127.0.0.1:8000;
182182
proxy_cache tmpcache;
183183
proxy_cache_key $uri$is_args$args;
184184
}
185185

186-
location ~ /purge(/.*) { //xml
186+
location ~ /purge(/.*) { #xml
187187
allow 127.0.0.1;
188188
deny all;
189189
proxy_cache_purge tmpcache $1$is_args$args;
190190
cache_purge_response_type xml;
191191
}
192192

193-
location ~ /purge2(/.*) { // json
193+
location ~ /purge2(/.*) { # json
194194
allow 127.0.0.1;
195195
deny all;
196196
proxy_cache_purge tmpcache $1$is_args$args;
@@ -199,19 +199,19 @@ Sample configuration (Optional)
199199

200200
server {
201201

202-
location / { //text
202+
location / { #text
203203
proxy_pass http://127.0.0.1:8000;
204204
proxy_cache tmpcache;
205205
proxy_cache_key $uri$is_args$args;
206206
}
207207

208-
location ~ /purge(/.*) { //text
208+
location ~ /purge(/.*) { #text
209209
allow 127.0.0.1;
210210
deny all;
211211
proxy_cache_purge tmpcache $1$is_args$args;
212212
}
213213

214-
location ~ /purge2(/.*) { /html/
214+
location ~ /purge2(/.*) { #html
215215
allow 127.0.0.1;
216216
deny all;
217217
proxy_cache_purge tmpcache $1$is_args$args;

ngx_cache_purge_module.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ static size_t ngx_http_cache_purge_content_type_html_size = sizeof(ngx_http_cach
5252
static size_t ngx_http_cache_purge_content_type_xml_size = sizeof(ngx_http_cache_purge_content_type_xml);
5353
static size_t ngx_http_cache_purge_content_type_text_size = sizeof(ngx_http_cache_purge_content_type_text);
5454

55-
static const char ngx_http_cache_purge_body_templ_json[] = "{\"Key\": \"%s\",\"Path\": \"%s\"}";
56-
static const char ngx_http_cache_purge_body_templ_html[] = "<html><head><title>Successful purge</title></head><body bgcolor=\"white\"><center><h1>Successful purge</h1><br>Key : %s<br>Path : %s</center></body></html>";
57-
static const char ngx_http_cache_purge_body_templ_xml[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><status><Key><![CDATA[%s]]></Key><Path><![CDATA[%s]]></Path></status>";
58-
static const char ngx_http_cache_purge_body_templ_text[] = "Key:%s\nPath:%s\n";
55+
static const char ngx_http_cache_purge_body_templ_json[] = "{\"Key\": \"%s\"}";
56+
static const char ngx_http_cache_purge_body_templ_html[] = "<html><head><title>Successful purge</title></head><body bgcolor=\"white\"><center><h1>Successful purge</h1><br>Key : %s</center></body></html>";
57+
static const char ngx_http_cache_purge_body_templ_xml[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><status><Key><![CDATA[%s]]></Key></status>";
58+
static const char ngx_http_cache_purge_body_templ_text[] = "Key:%s\n";
5959

6060
static size_t ngx_http_cache_purge_body_templ_json_size = sizeof(ngx_http_cache_purge_body_templ_json);
6161
static size_t ngx_http_cache_purge_body_templ_html_size = sizeof(ngx_http_cache_purge_body_templ_html);
@@ -1538,7 +1538,9 @@ ngx_http_cache_purge_send_response(ngx_http_request_t *r) {
15381538
return NGX_HTTP_INTERNAL_SERVER_ERROR;
15391539
}
15401540

1541-
p = ngx_snprintf(buf, resp_tmpl_len, resp_body , buf_keydata, r->cache->file.name.data);
1541+
1542+
//p = ngx_snprintf(buf, resp_tmpl_len, resp_body , buf_keydata, r->cache->file.name.data);
1543+
p = ngx_snprintf(buf, resp_tmpl_len, resp_body , buf_keydata, buf_keydata);
15421544
if (p == NULL) {
15431545
return NGX_HTTP_INTERNAL_SERVER_ERROR;
15441546
}
@@ -1572,7 +1574,6 @@ ngx_http_cache_purge_send_response(ngx_http_request_t *r) {
15721574
return rc;
15731575
}
15741576

1575-
15761577
return ngx_http_output_filter(r, &out);
15771578
}
15781579

t/resptype1.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ qr/\[(warn|error|crit|alert|emerg)\]/
112112
--- config eval: $::config
113113
--- request
114114
PURGE /purge/proxy/passwd
115-
--- error_code: 404
115+
--- error_code: 412
116116
--- response_headers
117117
Content-Type: text/html
118-
--- response_body_like: 404 Not Found
118+
--- response_body_like: 412 Precondition Failed
119119
--- timeout: 10
120120
--- no_error_log eval
121121
qr/\[(warn|error|crit|alert|emerg)\]/
@@ -178,7 +178,7 @@ PURGE /purge_json/proxy/passwd?t=7
178178
--- error_code: 200
179179
--- response_headers
180180
Content-Type: application/json
181-
--- response_body_like: {\"Key\": \"\/proxy\/passwd\?t=7\",\"Path\": \"\/tmp\/ngx_cache_purge_cache\/
181+
--- response_body_like: {\"Key\": \"\/proxy\/passwd\?t=7\"
182182
--- timeout: 10
183183
--- no_error_log eval
184184
qr/\[(warn|error|crit|alert|emerg)\]/
@@ -207,7 +207,7 @@ PURGE /purge_xml/proxy/passwd?t=8
207207
--- error_code: 200
208208
--- response_headers
209209
Content-Type: text/xml
210-
--- response_body_like: \<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><status><Key><\!\[CDATA\[\/proxy\/passwd\?t=8\]\]><\/Key><Path><\!\[CDATA\[\/tmp\/ngx_cache_purge_cache\/
210+
--- response_body_like: \<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><status><Key><\!\[CDATA\[\/proxy\/passwd\?t=8\]\]><\/Key>
211211
--- timeout: 10
212212
--- no_error_log eval
213213
qr/\[(warn|error|crit|alert|emerg)\]/

0 commit comments

Comments
 (0)