Mercurial > hg > nginx-tests
comparison proxy_variables.t @ 676:dbe5bc4b8b39
Tests: added tests for proxy module variables.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Sat, 29 Aug 2015 12:52:15 +0300 |
parents | ef2b435c1048 |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
675:42de9efd11ee | 676:dbe5bc4b8b39 |
---|---|
57 } | 57 } |
58 | 58 |
59 location /pnu { | 59 location /pnu { |
60 proxy_pass http://u/bad; | 60 proxy_pass http://u/bad; |
61 } | 61 } |
62 | |
63 location /vars { | |
64 proxy_pass http://127.0.0.1:8080/stub; | |
65 | |
66 add_header X-Proxy-Host $proxy_host; | |
67 add_header X-Proxy-Port $proxy_port; | |
68 add_header X-Proxy-Forwarded $proxy_add_x_forwarded_for; | |
69 } | |
70 | |
71 location /stub { } | |
62 } | 72 } |
63 } | 73 } |
64 | 74 |
65 EOF | 75 EOF |
66 | 76 |
77 $t->write_file('stub', ''); | |
67 $t->run_daemon(\&http_daemon, 8081); | 78 $t->run_daemon(\&http_daemon, 8081); |
68 $t->try_run('no upstream_connect_time')->plan(15); | 79 $t->try_run('no upstream_connect_time')->plan(18); |
69 | 80 |
70 $t->waitforsocket('127.0.0.1:8081'); | 81 $t->waitforsocket('127.0.0.1:8081'); |
71 | 82 |
72 ############################################################################### | 83 ############################################################################### |
73 | 84 |
74 my $re = qr/(\d\.\d{3})/; | 85 my $re = qr/(\d\.\d{3})/; |
75 my ($ct, $ht, $rt, $ct2, $ht2, $rt2); | 86 my ($ct, $ht, $rt, $ct2, $ht2, $rt2); |
87 | |
88 like(http_get('/vars'), qr/X-Proxy-Host:\s127\.0\.0\.1:8080/, 'proxy_host'); | |
89 like(http_get('/vars'), qr/X-Proxy-Port:\s8080/, 'proxy_port'); | |
90 like(http_xff('/vars', '192.0.2.1'), qr/X-Proxy-Forwarded:.*192\.0\.2\.1/, | |
91 'proxy_add_x_forwarded_for'); | |
76 | 92 |
77 ($ct, $ht) = get('/header'); | 93 ($ct, $ht) = get('/header'); |
78 cmp_ok($ct, '<', 1, 'connect time - slow response header'); | 94 cmp_ok($ct, '<', 1, 'connect time - slow response header'); |
79 cmp_ok($ht, '>=', 1, 'header time - slow response header'); | 95 cmp_ok($ht, '>=', 1, 'header time - slow response header'); |
80 | 96 |
108 sub get { | 124 sub get { |
109 my ($uri, %extra) = @_; | 125 my ($uri, %extra) = @_; |
110 my $re = $extra{many} ? qr/$re, $re?/ : $re; | 126 my $re = $extra{many} ? qr/$re, $re?/ : $re; |
111 my $r = http_get($uri); | 127 my $r = http_get($uri); |
112 $r =~ /X-Connect: $re/, $r =~ /X-Header: $re/, $r =~ /X-Response: $re/; | 128 $r =~ /X-Connect: $re/, $r =~ /X-Header: $re/, $r =~ /X-Response: $re/; |
129 } | |
130 | |
131 sub http_xff { | |
132 my ($uri, $xff) = @_; | |
133 return http(<<EOF); | |
134 GET $uri HTTP/1.0 | |
135 Host: localhost | |
136 X-Forwarded-For: $xff | |
137 | |
138 EOF | |
113 } | 139 } |
114 | 140 |
115 sub http_daemon { | 141 sub http_daemon { |
116 my ($port) = @_; | 142 my ($port) = @_; |
117 my $once = 1; | 143 my $once = 1; |