comparison proxy_bind.t @ 953:2bbab9bd73e5

Tests: added proxy_bind test with port.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 21 Jun 2016 18:38:32 +0300
parents e9064d691790
children 882267679006
comparison
equal deleted inserted replaced
952:e9064d691790 953:2bbab9bd73e5
24 24
25 plan(skip_all => 'win32') if $^O eq 'MSWin32'; 25 plan(skip_all => 'win32') if $^O eq 'MSWin32';
26 plan(skip_all => '127.0.0.2 local address required') 26 plan(skip_all => '127.0.0.2 local address required')
27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); 27 unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' );
28 28
29 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4) 29 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(5)
30 ->write_file_expand('nginx.conf', <<'EOF'); 30 ->write_file_expand('nginx.conf', <<'EOF');
31 31
32 %%TEST_GLOBALS%% 32 %%TEST_GLOBALS%%
33 33
34 daemon off; 34 daemon off;
61 61
62 location /var { 62 location /var {
63 proxy_bind $arg_b; 63 proxy_bind $arg_b;
64 proxy_pass http://127.0.0.1:%%PORT_1%%/; 64 proxy_pass http://127.0.0.1:%%PORT_1%%/;
65 } 65 }
66
67 location /port {
68 proxy_bind 127.0.0.2:$remote_port;
69 proxy_pass http://127.0.0.1:%%PORT_1%%/;
70 add_header X-Client-Port $remote_port;
71 }
66 } 72 }
67 73
68 server { 74 server {
69 listen 127.0.0.1:%%PORT_1%%; 75 listen 127.0.0.1:%%PORT_1%%;
70 server_name localhost; 76 server_name localhost;
71 77
72 location / { 78 location / {
73 add_header X-IP $remote_addr; 79 add_header X-IP $remote_addr;
80 add_header X-Port $remote_port;
74 } 81 }
75 } 82 }
76 } 83 }
77 84
78 EOF 85 EOF
85 like(http_get('/'), qr/X-IP: 127.0.0.1/, 'bind'); 92 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'); 93 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'); 94 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'); 95 like(http_get('/var?b=127.0.0.2'), qr/X-IP: 127.0.0.2/, 'bind var');
89 96
97 TODO: {
98 local $TODO = 'not yet' unless $t->has_version('1.11.2');
99
100 like(http_get('/port'), qr/Port: (\d+)(?!\d).*Port: \1/s, 'bind port');
101
102 }
103
90 ############################################################################### 104 ###############################################################################