Skip to content

Commit 576ce3b

Browse files
committed
fixed a bug in srcache_fetch_skip: when we skip srcache_fetch, we should not automatically skip srcache_store.
1 parent 6b08180 commit 576ce3b

File tree

2 files changed

+142
-1
lines changed

2 files changed

+142
-1
lines changed

src/ngx_http_srcache_filter_module.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,12 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
748748

749749
if (conf->req_cache_control) {
750750
if (ngx_http_srcache_request_no_cache(r) == NGX_OK) {
751+
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
752+
"srcache_fetch skipped due to request headers "
753+
"\"Cache-Control: no-cache\" or \"Pragma: no-cache\"");
754+
751755
/* register a ctx to give a chance to srcache_store to run */
756+
752757
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_filter_module));
753758

754759
if (ctx == NULL) {
@@ -770,6 +775,16 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
770775
"srcache_fetch skipped due to the true value fed into "
771776
"srcache_fetch_skip: \"%V\"", &skip);
772777

778+
/* register a ctx to give a chance to srcache_store to run */
779+
780+
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_filter_module));
781+
782+
if (ctx == NULL) {
783+
return NGX_HTTP_INTERNAL_SERVER_ERROR;
784+
}
785+
786+
ngx_http_set_ctx(r, ctx, ngx_http_srcache_filter_module);
787+
773788
return NGX_DECLINED;
774789
}
775790

t/fetch-skip.t

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Test::Nginx::Socket;
55

66
#repeat_each(2);
77

8-
plan tests => repeat_each() * 2 * blocks();
8+
plan tests => repeat_each() * (2 * blocks() + 10);
99

1010
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
1111

@@ -337,3 +337,129 @@ hello, world
337337
--- response_body chomp
338338
hello
339339
340+
341+
342+
=== TEST 19: flush all
343+
--- config
344+
location /flush {
345+
set $memc_cmd 'flush_all';
346+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
347+
}
348+
--- response_headers
349+
Content-Type: text/plain
350+
Content-Length: 4
351+
--- request
352+
GET /flush
353+
--- response_body eval: "OK\r\n"
354+
355+
356+
357+
=== TEST 20: basic fetch (cache miss)
358+
--- config
359+
location /foo {
360+
default_type text/css;
361+
srcache_fetch GET /memc $uri;
362+
srcache_store PUT /memc $uri;
363+
364+
echo hello;
365+
}
366+
367+
location /memc {
368+
internal;
369+
370+
set $memc_key $query_string;
371+
set $memc_exptime 300;
372+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
373+
}
374+
--- request
375+
GET /foo
376+
--- response_headers
377+
Content-Type: text/css
378+
Content-Length:
379+
--- response_body
380+
hello
381+
382+
383+
384+
=== TEST 21: basic fetch (cache hit)
385+
--- config
386+
location /foo {
387+
default_type text/css;
388+
srcache_fetch GET /memc $uri;
389+
srcache_store PUT /memc $uri;
390+
391+
echo world;
392+
}
393+
394+
location /memc {
395+
internal;
396+
397+
set $memc_key $query_string;
398+
set $memc_exptime 300;
399+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
400+
}
401+
--- request
402+
GET /foo
403+
--- response_headers
404+
Content-Type: text/css
405+
Content-Length: 6
406+
--- response_body
407+
hello
408+
409+
410+
411+
=== TEST 22: fetch skip true
412+
--- config
413+
location /foo {
414+
default_type text/css;
415+
srcache_fetch GET /memc $uri;
416+
srcache_store PUT /memc $uri;
417+
srcache_fetch_skip 1;
418+
419+
echo world;
420+
}
421+
422+
location /memc {
423+
internal;
424+
425+
set $memc_key $query_string;
426+
set $memc_exptime 300;
427+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
428+
}
429+
--- request
430+
GET /foo
431+
--- more_headers
432+
cache-control: No-Cache
433+
--- response_headers
434+
Content-Type: text/css
435+
Content-Length:
436+
--- response_body
437+
world
438+
439+
440+
441+
=== TEST 23: basic fetch (cache hit again)
442+
--- config
443+
location /foo {
444+
default_type text/css;
445+
srcache_fetch GET /memc $uri;
446+
srcache_store PUT /memc $uri;
447+
448+
echo world;
449+
}
450+
451+
location /memc {
452+
internal;
453+
454+
set $memc_key $query_string;
455+
set $memc_exptime 300;
456+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
457+
}
458+
--- request
459+
GET /foo
460+
--- response_headers
461+
Content-Type: text/css
462+
Content-Length: 6
463+
--- response_body
464+
world
465+

0 commit comments

Comments
 (0)