Mercurial > hg > nginx-tests
annotate proxy_bind.t @ 903:29aa547dd963
Tests: avoided potential hang in HTTP/2 unbuf request body tests.
Made sure to close client connections.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 19 Apr 2016 14:26:04 +0300 |
parents | 45d89d9c38a9 |
children | e9064d691790 |
rev | line source |
---|---|
641
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy_bind directive. |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 plan(skip_all => '127.0.0.2 local address required') |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4) |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 events { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 http { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 %%TEST_GLOBALS_HTTP%% |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 server { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 listen 127.0.0.1:8080; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 proxy_bind 127.0.0.2; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 location / { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 proxy_bind 127.0.0.1; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 proxy_pass http://127.0.0.1:8081/; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 location /inherit { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 proxy_pass http://127.0.0.1:8081/; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 location /off { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 proxy_bind off; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 proxy_pass http://127.0.0.1:8081/; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 location /var { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 proxy_bind $arg_b; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 proxy_pass http://127.0.0.1:8081/; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 server { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 listen 127.0.0.1:8081; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 server_name localhost; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 location / { |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 add_header X-IP $remote_addr; |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 } |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 EOF |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 $t->write_file('index.html', ''); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 $t->run(); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 ############################################################################### |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 like(http_get('/'), qr/X-IP: 127.0.0.1/, 'bind'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 like(http_get('/inherit'), qr/X-IP: 127.0.0.2/, 'bind inherit'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 like(http_get('/off'), qr/X-IP: 127.0.0.1/, 'bind off'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 like(http_get('/var?b=127.0.0.2'), qr/X-IP: 127.0.0.2/, 'bind var'); |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
45d89d9c38a9
Tests: http proxy_bind tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 ############################################################################### |