Mercurial > hg > nginx-tests
annotate proxy_xar.t @ 222:5b7883daaf82
Tests: use kill(9, $pid) on win32.
Change daemon termination to use kill(9, $pid) on win32, as normally used
kill(TERM, $pid) doesn't work with perlfork emulation and causes process
hangs.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 03 Jun 2012 04:56:14 +0400 |
parents | c0ae29632905 |
children | 6a0d934950bc |
rev | line source |
---|---|
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for proxy X-Accel-Redirect functionality. |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
121
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
107
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(8); |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 $t->write_file_expand('nginx.conf', <<'EOF'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
82
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
82
diff
changeset
|
29 |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 daemon off; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 events { |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 http { |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
82
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 server { |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 listen 127.0.0.1:8080; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server_name localhost; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 location /proxy { |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 proxy_pass http://127.0.0.1:8080/return-xar; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location /return-xar { |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 add_header X-Accel-Redirect /index.html; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 # this headers will be preserved on |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 # X-Accel-Redirect |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 add_header Content-Type text/blah; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 add_header Set-Cookie blah=blah; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 add_header Content-Disposition attachment; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 add_header Cache-Control no-cache; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 add_header Expires fake; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 add_header Accept-Ranges parrots; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 # others won't be |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 add_header Something other; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 return 204; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 EOF |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 $t->write_file('index.html', 'SEE-THIS'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 $t->run(); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 ############################################################################### |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 my $r = http_get('/proxy'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 like($r, qr/SEE-THIS/, 'X-Accel-Redirect works'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 like($r, qr/^Content-Type: text\/blah/m, 'Content-Type preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 like($r, qr/^Set-Cookie: blah=blah/m, 'Set-Cookie preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 like($r, qr/^Content-Disposition: attachment/m, 'Content-Disposition preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 like($r, qr/^Cache-Control: no-cache/m, 'Cache-Control preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 like($r, qr/^Expires: fake/m, 'Expires preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 like($r, qr/^Accept-Ranges: parrots/m, 'Accept-Ranges preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 unlike($r, qr/^Something/m, 'other headers stripped'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 ############################################################################### |