Mercurial > hg > nginx-tests
comparison spdy.t @ 487:c5ff54b56710
Tests: SPDY tests for empty header value.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 28 Oct 2014 20:56:21 +0300 |
parents | c2c1eb6d7a76 |
children | 8474d27c9147 |
comparison
equal
deleted
inserted
replaced
486:c2c1eb6d7a76 | 487:c5ff54b56710 |
---|---|
36 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | 36 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
37 | 37 |
38 my $t = Test::Nginx->new() | 38 my $t = Test::Nginx->new() |
39 ->has(qw/http proxy cache limit_conn rewrite spdy realip/); | 39 ->has(qw/http proxy cache limit_conn rewrite spdy realip/); |
40 | 40 |
41 $t->plan(79)->write_file_expand('nginx.conf', <<'EOF'); | 41 $t->plan(82)->write_file_expand('nginx.conf', <<'EOF'); |
42 | 42 |
43 %%TEST_GLOBALS%% | 43 %%TEST_GLOBALS%% |
44 | 44 |
45 daemon off; | 45 daemon off; |
46 | 46 |
87 add_header X-Body "$request_body"; | 87 add_header X-Body "$request_body"; |
88 proxy_pass http://127.0.0.1:8081/; | 88 proxy_pass http://127.0.0.1:8081/; |
89 proxy_cache NAME; | 89 proxy_cache NAME; |
90 proxy_cache_valid 1m; | 90 proxy_cache_valid 1m; |
91 } | 91 } |
92 location /header/ { | |
93 proxy_pass http://127.0.0.1:8083/; | |
94 } | |
92 location /proxy_buffering_off { | 95 location /proxy_buffering_off { |
93 proxy_pass http://127.0.0.1:8081/; | 96 proxy_pass http://127.0.0.1:8081/; |
94 proxy_cache NAME; | 97 proxy_cache NAME; |
95 proxy_cache_valid 1m; | 98 proxy_cache_valid 1m; |
96 proxy_buffering off; | 99 proxy_buffering off; |
110 } | 113 } |
111 } | 114 } |
112 | 115 |
113 EOF | 116 EOF |
114 | 117 |
115 $t->run(); | 118 $t->run_daemon(\&http_daemon); |
119 $t->run()->waitforsocket('127.0.0.1:8083'); | |
116 | 120 |
117 # file size is slightly beyond initial window size: 2**16 + 80 bytes | 121 # file size is slightly beyond initial window size: 2**16 + 80 bytes |
118 | 122 |
119 $t->write_file('t1.html', | 123 $t->write_file('t1.html', |
120 join('', map { sprintf "X%04dXXX", $_ } (1 .. 8202))); | 124 join('', map { sprintf "X%04dXXX", $_ } (1 .. 8202))); |
250 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | 254 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); |
251 | 255 |
252 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | 256 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; |
253 is($frame->{headers}->{'set-cookie'}, "val1\0val2", | 257 is($frame->{headers}->{'set-cookie'}, "val1\0val2", |
254 'response header with multiple values'); | 258 'response header with multiple values'); |
259 | |
260 # response header with multiple values - no empty values inside | |
261 | |
262 TODO: { | |
263 local $TODO = 'not yet'; | |
264 | |
265 $sess = new_session(); | |
266 $sid1 = spdy_stream($sess, { path => '/header/inside' }); | |
267 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
268 | |
269 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
270 is($frame->{headers}->{'x-foo'}, "val1\0val2", 'no empty header value inside'); | |
271 | |
272 $sid1 = spdy_stream($sess, { path => '/header/first' }); | |
273 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
274 | |
275 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
276 is($frame->{headers}->{'x-foo'}, "val1\0val2", 'no empty header value first'); | |
277 | |
278 $sid1 = spdy_stream($sess, { path => '/header/last' }); | |
279 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); | |
280 | |
281 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames; | |
282 is($frame->{headers}->{'x-foo'}, "val1\0val2", 'no empty header value last'); | |
283 | |
284 } | |
255 | 285 |
256 # $spdy | 286 # $spdy |
257 | 287 |
258 $sess = new_session(); | 288 $sess = new_session(); |
259 $sid1 = spdy_stream($sess, { path => '/spdy' }); | 289 $sid1 = spdy_stream($sess, { path => '/spdy' }); |
1102 "sdchcharset=utf-8charset=iso-8859-1,utf-,*,enq=0." | 1132 "sdchcharset=utf-8charset=iso-8859-1,utf-,*,enq=0." |
1103 ); | 1133 ); |
1104 } | 1134 } |
1105 | 1135 |
1106 ############################################################################### | 1136 ############################################################################### |
1137 | |
1138 # reply with multiple (also empty) header values | |
1139 | |
1140 sub http_daemon { | |
1141 my $server = IO::Socket::INET->new( | |
1142 Proto => 'tcp', | |
1143 LocalHost => '127.0.0.1', | |
1144 LocalPort => 8083, | |
1145 Listen => 5, | |
1146 Reuse => 1 | |
1147 ) | |
1148 or die "Can't create listening socket: $!\n"; | |
1149 | |
1150 local $SIG{PIPE} = 'IGNORE'; | |
1151 | |
1152 while (my $client = $server->accept()) { | |
1153 $client->autoflush(1); | |
1154 | |
1155 my $headers = ''; | |
1156 my $uri = ''; | |
1157 | |
1158 while (<$client>) { | |
1159 $headers .= $_; | |
1160 last if (/^\x0d?\x0a?$/); | |
1161 } | |
1162 | |
1163 next if $headers eq ''; | |
1164 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
1165 | |
1166 if ($uri eq '/inside') { | |
1167 | |
1168 print $client <<EOF; | |
1169 HTTP/1.1 200 OK | |
1170 Connection: close | |
1171 X-Foo: val1 | |
1172 X-Foo: | |
1173 X-Foo: val2 | |
1174 | |
1175 EOF | |
1176 | |
1177 } elsif ($uri eq '/first') { | |
1178 | |
1179 print $client <<EOF; | |
1180 HTTP/1.1 200 OK | |
1181 Connection: close | |
1182 X-Foo: | |
1183 X-Foo: val1 | |
1184 X-Foo: val2 | |
1185 | |
1186 EOF | |
1187 | |
1188 } elsif ($uri eq '/last') { | |
1189 | |
1190 print $client <<EOF; | |
1191 HTTP/1.1 200 OK | |
1192 Connection: close | |
1193 X-Foo: val1 | |
1194 X-Foo: val2 | |
1195 X-Foo: | |
1196 | |
1197 EOF | |
1198 } | |
1199 | |
1200 } continue { | |
1201 close $client; | |
1202 } | |
1203 } | |
1204 | |
1205 ############################################################################### |