# HG changeset patch # User Andrey Zelenkov # Date 1440841935 -10800 # Node ID dbe5bc4b8b39cd6b803d38d046e503a7ee58783b # Parent 42de9efd11ee2264d4cc29965c5a54f8710f5ccd Tests: added tests for proxy module variables. diff --git a/proxy_variables.t b/proxy_variables.t --- a/proxy_variables.t +++ b/proxy_variables.t @@ -59,13 +59,24 @@ http { 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 @@ EOF 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 @@ sub get { $r =~ /X-Connect: $re/, $r =~ /X-Header: $re/, $r =~ /X-Response: $re/; } +sub http_xff { + my ($uri, $xff) = @_; + return http(<