Skip to content

Commit 1acc6df

Browse files
committed
added t/store-max-size.t to cover the new srcache_store_max_size directive. also polished the debugging messages a bit.
1 parent 9b917d7 commit 1acc6df

File tree

2 files changed

+331
-5
lines changed

2 files changed

+331
-5
lines changed

src/ngx_http_srcache_filter_module.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ ngx_http_srcache_header_filter(ngx_http_request_t *r)
209209
&& r->headers_out.content_length_n > (off_t) slcf->store_max_size)
210210
{
211211
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
212-
"bypass because of too large content-length header: "
213-
"%O (limit is: %z)", r->headers_out.content_length_n,
214-
slcf->store_max_size);
212+
"srcache_store bypassed because of too large Content-Length "
213+
"response header: %O (limit is: %z)",
214+
r->headers_out.content_length_n, slcf->store_max_size);
215215

216216
return ngx_http_next_header_filter(r);
217217
}
@@ -390,8 +390,9 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
390390
&& ctx->body_length > slcf->store_max_size)
391391
{
392392
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
393-
"bypass because body exceeded maximum size: %z "
394-
"(limit is: %z)", ctx->body_length, slcf->store_max_size);
393+
"srcache_store bypassed because response body exceeded "
394+
"maximum size: %z (limit is: %z)",
395+
ctx->body_length, slcf->store_max_size);
395396

396397
ctx->store_response = 0;
397398

t/store-max-size.t

Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
# vi:filetype=
2+
3+
use lib 'lib';
4+
use Test::Nginx::Socket;
5+
6+
#repeat_each(2);
7+
8+
plan tests => repeat_each() * 2 * blocks();
9+
10+
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
11+
12+
no_shuffle();
13+
14+
run_tests();
15+
16+
__DATA__
17+
18+
=== TEST 1: flush all
19+
--- config
20+
location /flush {
21+
set $memc_cmd 'flush_all';
22+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
23+
}
24+
--- request
25+
GET /flush
26+
--- response_body eval: "OK\r\n"
27+
28+
29+
30+
=== TEST 2: just hit store_max_size
31+
--- config
32+
location /foo {
33+
default_type text/css;
34+
srcache_store PUT /memc $uri;
35+
srcache_store_max_size 6;
36+
37+
echo hello;
38+
}
39+
40+
location /memc {
41+
internal;
42+
43+
set $memc_cmd set;
44+
set $memc_key hit_store_max_size;
45+
set $memc_exptime 300;
46+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
47+
}
48+
--- request
49+
GET /foo
50+
--- response_body
51+
hello
52+
53+
54+
55+
=== TEST 3: check if /memc was invoked (just equal)
56+
--- config
57+
location /memc {
58+
set $memc_cmd get;
59+
set $memc_key hit_store_max_size;
60+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
61+
}
62+
--- request
63+
GET /memc
64+
--- response_body
65+
hello
66+
67+
68+
69+
=== TEST 4: flush all
70+
--- config
71+
location /flush {
72+
set $memc_cmd 'flush_all';
73+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
74+
}
75+
--- request
76+
GET /flush
77+
--- response_body eval: "OK\r\n"
78+
79+
80+
81+
=== TEST 5: less than store_max_size
82+
--- config
83+
location /foo {
84+
default_type text/css;
85+
srcache_store PUT /memc $uri;
86+
srcache_store_max_size 7;
87+
88+
echo hello;
89+
}
90+
91+
location /memc {
92+
internal;
93+
94+
set $memc_cmd set;
95+
set $memc_key less_than_store_max_size;
96+
set $memc_exptime 300;
97+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
98+
}
99+
--- request
100+
GET /foo
101+
--- response_body
102+
hello
103+
104+
105+
106+
=== TEST 6: check if /memc was invoked (less than)
107+
--- config
108+
location /memc {
109+
set $memc_cmd get;
110+
set $memc_key less_than_store_max_size;
111+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
112+
}
113+
--- request
114+
GET /memc
115+
--- response_body
116+
hello
117+
118+
119+
120+
=== TEST 7: flush all
121+
--- config
122+
location /flush {
123+
set $memc_cmd 'flush_all';
124+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
125+
}
126+
--- request
127+
GET /flush
128+
--- response_body eval: "OK\r\n"
129+
130+
131+
132+
=== TEST 8: just more than store_max_size
133+
--- config
134+
location /foo {
135+
default_type text/css;
136+
srcache_store PUT /memc $uri;
137+
srcache_store_max_size 5;
138+
139+
echo hello;
140+
}
141+
142+
location /memc {
143+
internal;
144+
145+
set $memc_cmd set;
146+
set $memc_key more_than_store_max_size;
147+
set $memc_exptime 300;
148+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
149+
}
150+
--- request
151+
GET /foo
152+
--- response_body
153+
hello
154+
155+
156+
157+
=== TEST 9: check if /memc was invoked (more than)
158+
--- config
159+
location /memc {
160+
set $memc_cmd get;
161+
set $memc_key more_than_store_max_size;
162+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
163+
}
164+
--- request
165+
GET /memc
166+
--- response_body_like: 404 Not Found
167+
--- error_code: 404
168+
169+
170+
171+
=== TEST 10: flush all
172+
--- config
173+
location /flush {
174+
set $memc_cmd 'flush_all';
175+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
176+
}
177+
--- request
178+
GET /flush
179+
--- response_body eval: "OK\r\n"
180+
181+
182+
183+
=== TEST 11: just more than store_max_size (explicit content-length)
184+
--- config
185+
location /foo.txt {
186+
default_type text/css;
187+
srcache_store PUT /memc $uri;
188+
srcache_store_max_size 5;
189+
}
190+
191+
location /memc {
192+
internal;
193+
194+
set $memc_cmd set;
195+
set $memc_key more_than_store_max_size;
196+
set $memc_exptime 300;
197+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
198+
}
199+
--- user_files
200+
>>> foo.txt
201+
hello
202+
--- request
203+
GET /foo.txt
204+
--- response_body
205+
hello
206+
207+
208+
209+
=== TEST 12: check if /memc was invoked (more than)
210+
--- config
211+
location /memc {
212+
set $memc_cmd get;
213+
set $memc_key more_than_store_max_size;
214+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
215+
}
216+
--- request
217+
GET /memc
218+
--- response_body_like: 404 Not Found
219+
--- error_code: 404
220+
221+
222+
223+
=== TEST 13: flush all
224+
--- config
225+
location /flush {
226+
set $memc_cmd 'flush_all';
227+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
228+
}
229+
--- request
230+
GET /flush
231+
--- response_body eval: "OK\r\n"
232+
233+
234+
235+
=== TEST 14: server-side config
236+
--- config
237+
srcache_store_max_size 3;
238+
location /foo.txt {
239+
default_type text/css;
240+
srcache_store PUT /memc $uri;
241+
}
242+
243+
location /memc {
244+
internal;
245+
246+
set $memc_cmd set;
247+
set $memc_key more_than_store_max_size;
248+
set $memc_exptime 300;
249+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
250+
}
251+
--- user_files
252+
>>> foo.txt
253+
abc
254+
--- request
255+
GET /foo.txt
256+
--- response_body
257+
abc
258+
259+
260+
261+
=== TEST 15: check if /memc was invoked (server-level config)
262+
--- config
263+
location /memc {
264+
set $memc_cmd get;
265+
set $memc_key more_than_store_max_size;
266+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
267+
}
268+
--- request
269+
GET /memc
270+
--- response_body_like: 404 Not Found
271+
--- error_code: 404
272+
273+
274+
275+
=== TEST 16: flush all
276+
--- config
277+
location /flush {
278+
set $memc_cmd 'flush_all';
279+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
280+
}
281+
--- request
282+
GET /flush
283+
--- response_body eval: "OK\r\n"
284+
285+
286+
287+
=== TEST 17: 0 means unlimited
288+
--- config
289+
srcache_store_max_size 3;
290+
location /foo.txt {
291+
default_type text/css;
292+
srcache_store PUT /memc $uri;
293+
srcache_store_max_size 0;
294+
}
295+
296+
location /memc {
297+
internal;
298+
299+
set $memc_cmd set;
300+
set $memc_key more_than_store_max_size;
301+
set $memc_exptime 300;
302+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
303+
}
304+
--- user_files
305+
>>> foo.txt
306+
hello, world
307+
--- request
308+
GET /foo.txt
309+
--- response_body
310+
hello, world
311+
312+
313+
314+
=== TEST 18: check if /memc was invoked (explicit unlimited)
315+
--- config
316+
location /memc {
317+
set $memc_cmd get;
318+
set $memc_key more_than_store_max_size;
319+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
320+
}
321+
--- request
322+
GET /memc
323+
--- response_body
324+
hello, world
325+

0 commit comments

Comments
 (0)