Skip to content

Commit c6eb4cd

Browse files
committed
added more tests for srcache_store_statuses; we now only cache 200, 301, and 302 responses by default.
1 parent 54fd50f commit c6eb4cd

File tree

3 files changed

+262
-5
lines changed

3 files changed

+262
-5
lines changed

src/ngx_http_srcache_store.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ ngx_http_srcache_header_filter(ngx_http_request_t *r)
194194
&& r->headers_out.status != NGX_HTTP_MOVED_PERMANENTLY)
195195
{
196196
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
197-
"srcache_store bypassed because of unmatched status code %i "
198-
"(only 200, 301, or 302 are accepted by default)",
197+
"srcache_store bypassed because of unmatched status "
198+
"code %i (only 200, 301, or 302 are accepted by default)",
199199
r->headers_out.status);
200200

201201
return ngx_http_srcache_next_header_filter(r);

t/status.t

Lines changed: 258 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() * 37;
6+
plan tests => repeat_each() * 81;
77

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

@@ -205,3 +205,260 @@ Content-Type: text/html
205205
--- response_body_like: 404 Not Found
206206
--- error_code: 404
207207
208+
209+
210+
=== TEST 10: flush all
211+
--- config
212+
location /flush {
213+
set $memc_cmd 'flush_all';
214+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
215+
}
216+
--- response_headers
217+
Content-Type: text/plain
218+
Content-Length: 4
219+
!Foo-Bar
220+
--- request
221+
GET /flush
222+
--- response_body eval: "OK\r\n"
223+
224+
225+
226+
=== TEST 11: basic fetch (cache 301 by default)
227+
--- config
228+
location /foo {
229+
default_type text/css;
230+
srcache_fetch GET /memc $uri;
231+
srcache_store PUT /memc $uri;
232+
233+
content_by_lua '
234+
ngx.redirect("/bah", 301)
235+
';
236+
}
237+
238+
location /memc {
239+
internal;
240+
241+
set $memc_key $query_string;
242+
set $memc_exptime 300;
243+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
244+
}
245+
--- request
246+
GET /foo HTTP/1.0
247+
--- response_headers
248+
Content-Type: text/html
249+
--- response_body_like: 301 Moved Permanently
250+
--- error_code: 301
251+
252+
253+
254+
=== TEST 12: inspect the cached item
255+
--- config
256+
location /memc {
257+
set $memc_key "/foo";
258+
set $memc_exptime 300;
259+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
260+
}
261+
--- request
262+
GET /memc
263+
--- response_headers
264+
Content-Type: text/html
265+
--- response_headers
266+
Content-Type: text/plain
267+
--- response_body_like
268+
^HTTP/1\.1 301 Moved Permanently\r
269+
Content-Type: text/html\r
270+
\r
271+
.*?301 Moved Permanently.*
272+
273+
274+
275+
=== TEST 13: 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+
--- response_headers
282+
Content-Type: text/plain
283+
Content-Length: 4
284+
!Foo-Bar
285+
--- request
286+
GET /flush
287+
--- response_body eval: "OK\r\n"
288+
289+
290+
291+
=== TEST 14: basic fetch (cache 302 by default)
292+
--- config
293+
location /foo {
294+
default_type text/css;
295+
srcache_fetch GET /memc $uri;
296+
srcache_store PUT /memc $uri;
297+
298+
content_by_lua '
299+
ngx.redirect("/bah", 302)
300+
';
301+
}
302+
303+
location /memc {
304+
internal;
305+
306+
set $memc_key $query_string;
307+
set $memc_exptime 300;
308+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
309+
}
310+
--- request
311+
GET /foo HTTP/1.0
312+
--- response_headers
313+
Content-Type: text/html
314+
--- response_body_like: 302 Found
315+
--- error_code: 302
316+
317+
318+
319+
=== TEST 15: inspect the cached item
320+
--- config
321+
location /memc {
322+
set $memc_key "/foo";
323+
set $memc_exptime 300;
324+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
325+
}
326+
--- request
327+
GET /memc
328+
--- response_headers
329+
Content-Type: text/html
330+
--- response_headers
331+
Content-Type: text/plain
332+
--- response_body_like
333+
^HTTP/1\.1 302 Moved Temporarily\r
334+
Content-Type: text/html\r
335+
\r
336+
.*?302 Found.*
337+
338+
339+
340+
=== TEST 16: flush all
341+
--- config
342+
location /flush {
343+
set $memc_cmd 'flush_all';
344+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
345+
}
346+
--- response_headers
347+
Content-Type: text/plain
348+
Content-Length: 4
349+
!Foo-Bar
350+
--- request
351+
GET /flush
352+
--- response_body eval: "OK\r\n"
353+
354+
355+
356+
=== TEST 17: basic fetch (201 not cached by default)
357+
--- config
358+
location /foo {
359+
default_type text/css;
360+
srcache_fetch GET /memc $uri;
361+
srcache_store PUT /memc $uri;
362+
363+
content_by_lua '
364+
ngx.status = 201
365+
ngx.say("Dog created")
366+
';
367+
}
368+
369+
location /memc {
370+
internal;
371+
372+
set $memc_key $query_string;
373+
set $memc_exptime 300;
374+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
375+
}
376+
--- request
377+
GET /foo HTTP/1.0
378+
--- response_headers
379+
Content-Type: text/css
380+
--- response_body
381+
Dog created
382+
--- error_code: 201
383+
384+
385+
386+
=== TEST 18: inspect the cached item
387+
--- config
388+
location /memc {
389+
set $memc_key "/foo";
390+
set $memc_exptime 300;
391+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
392+
}
393+
--- request
394+
GET /memc
395+
--- response_headers
396+
Content-Type: text/html
397+
--- response_headers
398+
Content-Type: text/html
399+
--- response_body_like: 404 Not Found
400+
--- error_code: 404
401+
402+
403+
404+
=== TEST 19: flush all
405+
--- config
406+
location /flush {
407+
set $memc_cmd 'flush_all';
408+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
409+
}
410+
--- response_headers
411+
Content-Type: text/plain
412+
Content-Length: 4
413+
!Foo-Bar
414+
--- request
415+
GET /flush
416+
--- response_body eval: "OK\r\n"
417+
418+
419+
420+
=== TEST 20: basic fetch (explicitly do not cache 302)
421+
--- config
422+
location /foo {
423+
default_type text/css;
424+
srcache_fetch GET /memc $uri;
425+
srcache_store PUT /memc $uri;
426+
srcache_store_statuses 301 200;
427+
428+
content_by_lua '
429+
ngx.redirect("/bah", 302)
430+
';
431+
}
432+
433+
location /memc {
434+
internal;
435+
436+
set $memc_key $query_string;
437+
set $memc_exptime 300;
438+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
439+
}
440+
--- request
441+
GET /foo HTTP/1.0
442+
--- response_headers
443+
Content-Type: text/html
444+
--- response_body_like: 302 Found
445+
--- error_code: 302
446+
447+
448+
449+
=== TEST 21: inspect the cached item
450+
--- config
451+
location /memc {
452+
set $memc_key "/foo";
453+
set $memc_exptime 300;
454+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
455+
}
456+
--- request
457+
GET /memc
458+
--- response_headers
459+
Content-Type: text/html
460+
--- response_headers
461+
Content-Type: text/html
462+
--- response_body_like: 404 Not Found
463+
--- error_code: 404
464+

util/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ ngx-build $force $version \
2929
--add-module=$root/../drizzle-nginx-module \
3030
--add-module=$root/../postgres-nginx-module \
3131
--add-module=$root/../memc-nginx-module \
32-
--add-module=$root/../ndk-nginx-module \
33-
--with-debug || exit 1
32+
--add-module=$root/../ndk-nginx-module #\
33+
#--with-debug || exit 1
3434
#--add-module=/home/agentz/git/dodo/utils/dodo-hook \
3535
#--add-module=$home/work/ngx_http_auth_request-0.1 #\
3636
#--with-rtsig_module

0 commit comments

Comments
 (0)