Mercurial > hg > nginx-tests
comparison headers.t @ 515:9f972a386434
Tests: expires with variables.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 15 Dec 2014 12:03:09 +0300 |
parents | a610ee837190 |
children | 907e89fba9c3 |
comparison
equal
deleted
inserted
replaced
514:42d447013553 | 515:9f972a386434 |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 | 2 |
3 # (C) Sergey Kandaurov | 3 # (C) Sergey Kandaurov |
4 # (C) Maxim Dounin | |
4 # (C) Nginx, Inc. | 5 # (C) Nginx, Inc. |
5 | 6 |
6 # Tests for headers module. | 7 # Tests for headers module. |
7 | 8 |
8 ############################################################################### | 9 ############################################################################### |
39 listen 127.0.0.1:8080; | 40 listen 127.0.0.1:8080; |
40 server_name localhost; | 41 server_name localhost; |
41 | 42 |
42 add_header X-URI $uri; | 43 add_header X-URI $uri; |
43 add_header X-Always $uri always; | 44 add_header X-Always $uri always; |
44 expires epoch; | 45 expires epoch; |
45 | 46 |
46 location /t1 { | 47 location /t1 { |
47 } | 48 } |
48 | 49 |
49 location /nx { | 50 location /nx { |
61 expires off; | 62 expires off; |
62 } | 63 } |
63 | 64 |
64 location /access { | 65 location /access { |
65 expires 2048; | 66 expires 2048; |
67 | |
68 location /access_inner { | |
69 # inherited from outer | |
70 } | |
66 } | 71 } |
67 | 72 |
68 location /negative { | 73 location /negative { |
69 expires -2048; | 74 expires -2048; |
70 } | 75 } |
74 } | 79 } |
75 | 80 |
76 location /modified { | 81 location /modified { |
77 expires modified 2048; | 82 expires modified 2048; |
78 } | 83 } |
84 | |
85 location /var { | |
86 expires $arg_e; | |
87 | |
88 location /var_inner { | |
89 # inherited from outer | |
90 } | |
91 | |
92 location /var_modified { | |
93 expires modified $arg_e; | |
94 } | |
95 } | |
79 } | 96 } |
80 } | 97 } |
81 | 98 |
82 EOF | 99 EOF |
83 | 100 |
84 $t->write_file('t1', ''); | 101 $t->write_file('t1', ''); |
85 $t->write_file('epoch', ''); | 102 $t->write_file('epoch', ''); |
86 $t->write_file('max', ''); | 103 $t->write_file('max', ''); |
87 $t->write_file('off', ''); | 104 $t->write_file('off', ''); |
88 $t->write_file('access', ''); | 105 $t->write_file('access', ''); |
106 $t->write_file('access_inner', ''); | |
89 $t->write_file('negative', ''); | 107 $t->write_file('negative', ''); |
90 $t->write_file('daily', ''); | 108 $t->write_file('daily', ''); |
91 $t->write_file('modified', ''); | 109 $t->write_file('modified', ''); |
110 $t->write_file('var', ''); | |
111 $t->write_file('var_inner', ''); | |
112 $t->write_file('var_modified', ''); | |
92 | 113 |
93 $t->try_run('no add_header always')->plan(13); | 114 $t->try_run('no add_header always or expires with variable')->plan(25); |
94 | 115 |
95 ############################################################################### | 116 ############################################################################### |
96 | 117 |
97 my $r; | 118 my $r; |
98 | 119 |
112 | 133 |
113 like(http_get('/epoch'), qr/Expires:.*1970/, 'expires epoch'); | 134 like(http_get('/epoch'), qr/Expires:.*1970/, 'expires epoch'); |
114 like(http_get('/max'), qr/Expires:.*2037/, 'expires max'); | 135 like(http_get('/max'), qr/Expires:.*2037/, 'expires max'); |
115 unlike(http_get('/off'), qr/Expires:/, 'expires off'); | 136 unlike(http_get('/off'), qr/Expires:/, 'expires off'); |
116 like(http_get('/access'), qr/max-age=2048/, 'expires access'); | 137 like(http_get('/access'), qr/max-age=2048/, 'expires access'); |
138 like(http_get('/access_inner'), qr/max-age=2048/, 'expires inner'); | |
117 like(http_get('/negative'), qr/no-cache/, 'expires negative'); | 139 like(http_get('/negative'), qr/no-cache/, 'expires negative'); |
118 like(http_get('/daily'), qr/Expires:.*:33 GMT/, 'expires daily'); | 140 like(http_get('/daily'), qr/Expires:.*:33 GMT/, 'expires daily'); |
119 like(http_get('/modified'), qr/max-age=204./, 'expires modified'); | 141 like(http_get('/modified'), qr/max-age=204./, 'expires modified'); |
120 | 142 |
143 # expires with variables | |
144 | |
145 like(http_get('/var?e=epoch'), qr/Expires:.*1970/, 'expires var epoch'); | |
146 like(http_get('/var?e=max'), qr/Expires:.*2037/, 'expires var max'); | |
147 unlike(http_get('/var?e=off'), qr/Expires:/, 'expires var off'); | |
148 like(http_get('/var?e=2048'), qr/max-age=2048/, 'expires var access'); | |
149 like(http_get('/var_inner?e=2048'), qr/max-age=2048/, 'expires var inner'); | |
150 like(http_get('/var?e=-2048'), qr/no-cache/, 'expires var negative'); | |
151 like(http_get('/var?e=@33s'), qr/Expires:.*:33 GMT/, 'expires var daily'); | |
152 like(http_get('/var_modified?e=2048'), qr/max-age=204./, | |
153 'expires var modified'); | |
154 | |
155 # some invalid cases | |
156 | |
157 unlike(http_get('/var'), qr/Expires/, 'expires var empty'); | |
158 unlike(http_get('/var?e=bad'), qr/Expires/, 'expires var bad'); | |
159 unlike(http_get('/var_modified?e=epoch'), qr/Expires/, | |
160 'expires var modified epoch'); | |
161 | |
121 ############################################################################### | 162 ############################################################################### |