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