Mercurial > hg > nginx-tests
comparison proxy_bind.t @ 641:45d89d9c38a9
Tests: http proxy_bind tests.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Wed, 05 Aug 2015 18:31:33 +0300 |
parents | |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
640:1d1eaf5ce064 | 641:45d89d9c38a9 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Andrey Zelenkov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for http proxy_bind 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 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | |
26 plan(skip_all => '127.0.0.2 local address required') | |
27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); | |
28 | |
29 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4) | |
30 ->write_file_expand('nginx.conf', <<'EOF'); | |
31 | |
32 %%TEST_GLOBALS%% | |
33 | |
34 daemon off; | |
35 | |
36 events { | |
37 } | |
38 | |
39 http { | |
40 %%TEST_GLOBALS_HTTP%% | |
41 | |
42 server { | |
43 listen 127.0.0.1:8080; | |
44 server_name localhost; | |
45 | |
46 proxy_bind 127.0.0.2; | |
47 | |
48 location / { | |
49 proxy_bind 127.0.0.1; | |
50 proxy_pass http://127.0.0.1:8081/; | |
51 } | |
52 | |
53 location /inherit { | |
54 proxy_pass http://127.0.0.1:8081/; | |
55 } | |
56 | |
57 location /off { | |
58 proxy_bind off; | |
59 proxy_pass http://127.0.0.1:8081/; | |
60 } | |
61 | |
62 location /var { | |
63 proxy_bind $arg_b; | |
64 proxy_pass http://127.0.0.1:8081/; | |
65 } | |
66 } | |
67 | |
68 server { | |
69 listen 127.0.0.1:8081; | |
70 server_name localhost; | |
71 | |
72 location / { | |
73 add_header X-IP $remote_addr; | |
74 } | |
75 } | |
76 } | |
77 | |
78 EOF | |
79 | |
80 $t->write_file('index.html', ''); | |
81 $t->run(); | |
82 | |
83 ############################################################################### | |
84 | |
85 like(http_get('/'), qr/X-IP: 127.0.0.1/, 'bind'); | |
86 like(http_get('/inherit'), qr/X-IP: 127.0.0.2/, 'bind inherit'); | |
87 like(http_get('/off'), qr/X-IP: 127.0.0.1/, 'bind off'); | |
88 like(http_get('/var?b=127.0.0.2'), qr/X-IP: 127.0.0.2/, 'bind var'); | |
89 | |
90 ############################################################################### |