Mercurial > hg > nginx-tests
comparison proxy_redirect.t @ 193:50063559d85a
Tests: proxy_redirect and Refresh header.
author | Valentin Bartenev <ne@vbart.ru> |
---|---|
date | Tue, 10 Jan 2012 02:06:15 +0400 |
parents | 1613a63b5100 |
children | 3f59e6a843bd |
comparison
equal
deleted
inserted
replaced
192:f2a48c528b3b | 193:50063559d85a |
---|---|
20 ############################################################################### | 20 ############################################################################### |
21 | 21 |
22 select STDERR; $| = 1; | 22 select STDERR; $| = 1; |
23 select STDOUT; $| = 1; | 23 select STDOUT; $| = 1; |
24 | 24 |
25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(6); | 25 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(12); |
26 | 26 |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | 27 $t->write_file_expand('nginx.conf', <<'EOF'); |
28 | 28 |
29 %%TEST_GLOBALS%% | 29 %%TEST_GLOBALS%% |
30 | 30 |
66 server { | 66 server { |
67 listen 127.0.0.1:8081; | 67 listen 127.0.0.1:8081; |
68 server_name localhost; | 68 server_name localhost; |
69 | 69 |
70 location / { | 70 location / { |
71 add_header Refresh "7; url=http://127.0.0.1:8081$uri"; | |
71 return http://127.0.0.1:8081$uri; | 72 return http://127.0.0.1:8081$uri; |
72 } | 73 } |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
83 is(http_get_location('http://127.0.0.1:8080/impl_default/test.html'), | 84 is(http_get_location('http://127.0.0.1:8080/impl_default/test.html'), |
84 'http://127.0.0.1:8080/impl_default/test.html', 'implicit default'); | 85 'http://127.0.0.1:8080/impl_default/test.html', 'implicit default'); |
85 is(http_get_location('http://127.0.0.1:8080/expl_default/test.html'), | 86 is(http_get_location('http://127.0.0.1:8080/expl_default/test.html'), |
86 'http://127.0.0.1:8080/expl_default/test.html', 'explicit default'); | 87 'http://127.0.0.1:8080/expl_default/test.html', 'explicit default'); |
87 | 88 |
89 is(http_get_refresh('http://127.0.0.1:8080/impl_default/test.html'), | |
90 '7; url=/impl_default/test.html', 'implicit default (refresh)'); | |
91 is(http_get_refresh('http://127.0.0.1:8080/expl_default/test.html'), | |
92 '7; url=/expl_default/test.html', 'explicit default (refresh)'); | |
93 | |
88 is(http_get_location('http://127.0.0.1:8080/var_in_second/test.html'), | 94 is(http_get_location('http://127.0.0.1:8080/var_in_second/test.html'), |
89 'http://127.0.0.1:8080/var_here/test.html', 'variable in second arg'); | 95 'http://127.0.0.1:8080/var_here/test.html', 'variable in second arg'); |
96 is(http_get_refresh('http://127.0.0.1:8080/var_in_second/test.html'), | |
97 '7; url=/var_here/test.html', 'variable in second arg (refresh)'); | |
90 | 98 |
91 TODO:{ | 99 TODO: { |
92 local $TODO = 'support variables in first argument'; | 100 local $TODO = 'support variables in first argument'; |
93 | 101 |
94 is(http_get_location('http://127.0.0.1:8080/var_here/test.html'), | 102 is(http_get_location('http://127.0.0.1:8080/var_here/test.html'), |
95 'http://127.0.0.1:8080/replaced/test.html', 'variable in first arg'); | 103 'http://127.0.0.1:8080/replaced/test.html', 'variable in first arg'); |
104 is(http_get_refresh('http://127.0.0.1:8080/var_here/test.html'), | |
105 '7; url=/replaced/test.html', 'variable in first arg (refresh)'); | |
96 | 106 |
97 } | 107 } |
98 | 108 |
99 TODO:{ | 109 TODO: { |
100 local $TODO = 'support for regular expressions'; | 110 local $TODO = 'support for regular expressions'; |
101 | 111 |
102 is(http_get_location('http://127.0.0.1:8080/ReeegEX/test.html'), | 112 is(http_get_location('http://127.0.0.1:8080/ReeegEX/test.html'), |
103 'http://127.0.0.1:8080/replaced/test.html', 'caseless regexp'); | 113 'http://127.0.0.1:8080/replaced/test.html', 'caseless regexp'); |
104 is(http_get_location('http://127.0.0.1:8080/regex_w_captures/test.html'), | 114 is(http_get_location('http://127.0.0.1:8080/regex_w_captures/test.html'), |
105 'http://127.0.0.1:8080/captures/test.html', 'regexp w/captures'); | 115 'http://127.0.0.1:8080/captures/test.html', 'regexp w/captures'); |
106 | 116 |
107 } | 117 } |
108 | 118 |
119 TODO: { | |
120 local $TODO = 'regular expressions and Refresh header'; | |
121 | |
122 is(http_get_refresh('http://127.0.0.1:8080/ReeegEX/test.html'), | |
123 '7; url=/replaced/test.html', 'caseless regexp (refresh)'); | |
124 is(http_get_refresh('http://127.0.0.1:8080/regex_w_captures/test.html'), | |
125 '7; url=http://127.0.0.1:8080/captures/test.html', | |
126 'regexp w/captures (refresh)'); | |
127 | |
128 } | |
109 | 129 |
110 ############################################################################### | 130 ############################################################################### |
111 | 131 |
112 sub http_get_location { | 132 sub http_get_location { |
113 my ($url) = @_; | 133 my ($url) = @_; |
114 http_get($url) =~ /^Location:\s(.+?)\x0d?$/mi; | 134 http_get($url) =~ /^Location:\s(.+?)\x0d?$/mi; |
115 return $1; | 135 return $1; |
116 } | 136 } |
137 | |
138 sub http_get_refresh { | |
139 my ($url) = @_; | |
140 http_get($url) =~ /^Refresh:\s(.+?)\x0d?$/mi; | |
141 return $1; | |
142 } |