Mercurial > hg > nginx-tests
comparison proxy_cache_convert_head.t @ 780:5a0bba53854b
Tests: proxy_cache_convert_head tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 11 Nov 2015 15:55:19 +0300 |
parents | |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
779:ca2db52ae97f | 780:5a0bba53854b |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for http proxy cache with proxy_cache_convert_head directive. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http proxy cache shmem/) | |
26 ->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 proxy_cache_path %%TESTDIR%%/cache levels=1:2 | |
39 keys_zone=NAME:1m; | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080; | |
43 server_name localhost; | |
44 | |
45 proxy_cache NAME; | |
46 | |
47 proxy_cache_key $request_uri; | |
48 | |
49 proxy_cache_valid 200 302 2s; | |
50 | |
51 add_header X-Cache-Status $upstream_cache_status; | |
52 | |
53 location / { | |
54 proxy_pass http://127.0.0.1:8081/t.html; | |
55 proxy_cache_convert_head off; | |
56 | |
57 location /inner { | |
58 proxy_pass http://127.0.0.1:8081/t.html; | |
59 proxy_cache_convert_head on; | |
60 } | |
61 } | |
62 | |
63 location /on { | |
64 proxy_pass http://127.0.0.1:8081/t.html; | |
65 proxy_cache_convert_head on; | |
66 } | |
67 } | |
68 server { | |
69 listen 127.0.0.1:8081; | |
70 server_name localhost; | |
71 | |
72 location / { | |
73 add_header X-Method $request_method; | |
74 } | |
75 } | |
76 } | |
77 | |
78 EOF | |
79 | |
80 $t->write_file('t.html', 'SEE-THIS'); | |
81 | |
82 $t->try_run('no proxy_cache_convert_head')->plan(8); | |
83 | |
84 ############################################################################### | |
85 | |
86 like(http_get('/'), qr/X-Method: GET/, 'get'); | |
87 like(http_head('/?2'), qr/X-Method: HEAD/, 'head'); | |
88 like(http_head('/?2'), qr/HIT/, 'head cached'); | |
89 unlike(http_get('/?2'), qr/SEE-THIS/, 'get after head'); | |
90 | |
91 like(http_get('/on'), qr/X-Method: GET/, 'on - get'); | |
92 like(http_head('/on?2'), qr/X-Method: GET/, 'on - head'); | |
93 | |
94 like(http_get('/inner'), qr/X-Method: GET/, 'inner - get'); | |
95 like(http_head('/inner?2'), qr/X-Method: GET/, 'inner - head'); | |
96 | |
97 ############################################################################### |