Mercurial > hg > nginx-tests
changeset 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 | 42de9efd11ee |
children | 5d258aa5ebc5 |
files | proxy_variables.t |
diffstat | 1 files changed, 27 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/proxy_variables.t Fri Sep 04 14:45:15 2015 +0300 +++ b/proxy_variables.t Sat Aug 29 12:52:15 2015 +0300 @@ -59,13 +59,24 @@ location /pnu { proxy_pass http://u/bad; } + + location /vars { + proxy_pass http://127.0.0.1:8080/stub; + + add_header X-Proxy-Host $proxy_host; + add_header X-Proxy-Port $proxy_port; + add_header X-Proxy-Forwarded $proxy_add_x_forwarded_for; + } + + location /stub { } } } EOF +$t->write_file('stub', ''); $t->run_daemon(\&http_daemon, 8081); -$t->try_run('no upstream_connect_time')->plan(15); +$t->try_run('no upstream_connect_time')->plan(18); $t->waitforsocket('127.0.0.1:8081'); @@ -74,6 +85,11 @@ my $re = qr/(\d\.\d{3})/; my ($ct, $ht, $rt, $ct2, $ht2, $rt2); +like(http_get('/vars'), qr/X-Proxy-Host:\s127\.0\.0\.1:8080/, 'proxy_host'); +like(http_get('/vars'), qr/X-Proxy-Port:\s8080/, 'proxy_port'); +like(http_xff('/vars', '192.0.2.1'), qr/X-Proxy-Forwarded:.*192\.0\.2\.1/, + 'proxy_add_x_forwarded_for'); + ($ct, $ht) = get('/header'); cmp_ok($ct, '<', 1, 'connect time - slow response header'); cmp_ok($ht, '>=', 1, 'header time - slow response header'); @@ -112,6 +128,16 @@ $r =~ /X-Connect: $re/, $r =~ /X-Header: $re/, $r =~ /X-Response: $re/; } +sub http_xff { + my ($uri, $xff) = @_; + return http(<<EOF); +GET $uri HTTP/1.0 +Host: localhost +X-Forwarded-For: $xff + +EOF +} + sub http_daemon { my ($port) = @_; my $once = 1;