Skip to content

Commit cf9669a

Browse files
committed
bugfix: responses with a status code smaller than all the status codes specified in the srcache_store_statuses directive were not skipped as expected. thanks Lanshun Zhou for the patch in github pull #19.
1 parent fb4b659 commit cf9669a

File tree

2 files changed

+78
-18
lines changed

2 files changed

+78
-18
lines changed

src/ngx_http_srcache_store.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ngx_http_srcache_header_filter(ngx_http_request_t *r)
3535
ngx_http_srcache_loc_conf_t *slcf;
3636
ngx_http_post_subrequest_t *ps;
3737
ngx_str_t skip;
38-
ngx_int_t *sp; /* status pointer */
38+
ngx_uint_t *sp; /* status pointer */
3939

4040
dd_enter();
4141
dd("srcache header filter");
@@ -177,27 +177,23 @@ ngx_http_srcache_header_filter(ngx_http_request_t *r)
177177

178178
if (slcf->store_statuses != NULL) {
179179

180-
sp = slcf->store_statuses;
181-
for ( ; *sp; sp++) {
180+
sp = (ngx_uint_t *) slcf->store_statuses;
182181

183-
/* store_stauses are in the descent order */
184-
if (r->headers_out.status < (ngx_uint_t) *sp) {
185-
continue;
186-
}
187-
188-
if (r->headers_out.status > (ngx_uint_t) *sp) {
189-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
190-
"srcache_store bypassed because of unmatched "
191-
"status code %i with srcache_store_statuses",
192-
r->headers_out.status);
182+
while (r->headers_out.status < *sp) {
183+
sp++;
184+
}
193185

194-
return ngx_http_srcache_next_header_filter(r);
195-
}
186+
if (*sp == 0 || r->headers_out.status > *sp) {
187+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
188+
"srcache_store bypassed because of unmatched "
189+
"status code %ui with srcache_store_statuses",
190+
r->headers_out.status);
196191

197-
/* r->headers_out.status == (ngx_uint_t) *sp */
198-
break;
192+
return ngx_http_srcache_next_header_filter(r);
199193
}
200194

195+
/* r->headers_out.status == (ngx_uint_t) *sp */
196+
201197
} else {
202198

203199
if (r->headers_out.status != NGX_HTTP_OK

t/status.t

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use lib 'lib';
44
use Test::Nginx::Socket;
55

6-
plan tests => repeat_each() * 81;
6+
plan tests => repeat_each() * 92;
77

88
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
99

@@ -464,3 +464,67 @@ Content-Type: text/html
464464
--- response_body_like: 404 Not Found
465465
--- error_code: 404
466466
467+
468+
469+
=== TEST 22: flush all
470+
--- config
471+
location /flush {
472+
set $memc_cmd 'flush_all';
473+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
474+
}
475+
--- response_headers
476+
Content-Type: text/plain
477+
Content-Length: 4
478+
!Foo-Bar
479+
--- request
480+
GET /flush
481+
--- response_body eval: "OK\r\n"
482+
483+
484+
485+
=== TEST 23: basic fetch (explicitly do not cache 302, and store_statuses are all bigger than 302)
486+
github pull #19
487+
--- config
488+
location /foo {
489+
default_type text/css;
490+
srcache_fetch GET /memc $uri;
491+
srcache_store PUT /memc $uri;
492+
srcache_store_statuses 303 304;
493+
494+
content_by_lua '
495+
ngx.redirect("/bah", 302)
496+
';
497+
}
498+
499+
location /memc {
500+
internal;
501+
502+
set $memc_key $query_string;
503+
set $memc_exptime 300;
504+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
505+
}
506+
--- request
507+
GET /foo HTTP/1.0
508+
--- response_headers
509+
Content-Type: text/html
510+
--- response_body_like: 302 Found
511+
--- error_code: 302
512+
513+
514+
515+
=== TEST 24: inspect the cached item
516+
--- config
517+
location /memc {
518+
set $memc_key "/foo";
519+
set $memc_exptime 300;
520+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
521+
}
522+
--- request
523+
GET /memc
524+
--- response_headers
525+
Content-Type: text/html
526+
--- response_headers
527+
Content-Type: text/html
528+
--- response_body_like: 404 Not Found
529+
--- error_code: 404
530+

0 commit comments

Comments
 (0)