Skip to content

Commit

Permalink
feature: now the value specified in srcache_store_skip is checked aga…
Browse files Browse the repository at this point in the history
…in right before the srcache_store subrequest is issued. thanks Eldar Zaitov for the patch in #25.
  • Loading branch information
agentzh committed Jan 8, 2014
1 parent 39b79c2 commit ad112da
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/ngx_http_srcache_store.c
Expand Up @@ -253,6 +253,7 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
ngx_http_srcache_ctx_t *ctx, *pr_ctx;
ngx_int_t rc;
ngx_str_t skip;
ngx_chain_t *cl;
ngx_http_srcache_loc_conf_t *slcf;
size_t len;
Expand Down Expand Up @@ -449,6 +450,19 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
#endif

if (slcf->store_skip != NULL
&& ngx_http_complex_value(r, slcf->store_skip, &skip) == NGX_OK
&& skip.len
&& (skip.len != 1 || skip.data[0] != '0'))
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"srcache_store skipped due to the true value in "
"srcache_store_skip: \"%V\"", &skip);

ctx->store_response = 0;
goto done;
}

rc = ngx_http_srcache_store_subrequest(r, ctx);

if (rc != NGX_OK) {
Expand Down
64 changes: 63 additions & 1 deletion t/store-skip.t
Expand Up @@ -5,7 +5,7 @@ use Test::Nginx::Socket;

#repeat_each(2);

plan tests => repeat_each() * (2 * blocks() + 6);
plan tests => repeat_each() * (2 * blocks() + 8);

$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;

Expand Down Expand Up @@ -371,3 +371,65 @@ Content-Length: 13
--- response_body
hello, world
=== TEST 20: flush all
--- config
location /flush {
set $memc_cmd 'flush_all';
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /flush
--- response_body eval: "OK\r\n"
=== TEST 21: store_skip is true in the last minute
--- config
location /foo {
default_type text/css;
srcache_store PUT /memc $uri;
set $skip '';
srcache_store_skip $skip;
content_by_lua '
ngx.say("hello")
ngx.say("world")
ngx.var.skip = 1
';
add_header X-Store-Status $srcache_store_status;
}
location /memc {
internal;
set $memc_cmd set;
set $memc_key key;
set $memc_exptime 300;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /foo
--- response_body
hello
world
--- response_headers
X-Store-Status: STORE
--- error_log
srcache_store skipped due to the true value in srcache_store_skip: "1"
=== TEST 22: check if /memc was invoked
--- config
location /memc {
set $memc_cmd get;
set $memc_key key;
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
}
--- request
GET /memc
--- response_body_like: 404 Not Found
--- error_code: 404

0 comments on commit ad112da

Please sign in to comment.