annotate spdy.t @ 377:ba95a443ff1f

Tests: improved spdy test robustness. Give raw_read() a little more chance to complete.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 24 Feb 2014 14:09:16 +0400
parents ab2d8abea393
children f42de3a9fd74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
374
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for SPDY protocol version 3.1.
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 use IO::Select;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 ###############################################################################
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 eval {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 require Compress::Raw::Zlib;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 Compress::Raw::Zlib->Z_OK;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 Compress::Raw::Zlib->Z_SYNC_FLUSH;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 Compress::Raw::Zlib->Z_NO_COMPRESSION;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 Compress::Raw::Zlib->WANT_GZIP_OR_ZLIB;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 };
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 plan(skip_all => 'Compress::Raw::Zlib not installed') if $@;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 plan(skip_all => 'win32') if $^O eq 'MSWin32';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 my $t = Test::Nginx->new()->has(qw/http proxy cache limit_conn rewrite spdy/);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 plan(skip_all => 'no SPDY/3.1') unless $t->has_version('1.5.10');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 $t->plan(72)->write_file_expand('nginx.conf', <<'EOF');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 %%TEST_GLOBALS%%
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 daemon off;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 events {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 http {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 %%TEST_GLOBALS_HTTP%%
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:10m;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 limit_conn_zone $binary_remote_addr zone=conn:1m;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 server {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 listen 127.0.0.1:8080 spdy;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 listen 127.0.0.1:8081;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 server_name localhost;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 location /s {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 add_header X-Header X-Foo;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 return 200 'body';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 location /spdy {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 return 200 $spdy;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 location /prio {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 return 200 $spdy_request_priority;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 location /chunk_size {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 spdy_chunk_size 1;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 return 200 'body';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 location /redirect {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 error_page 405 /s;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 return 405;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 location /proxy {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 add_header X-Body "$request_body";
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 proxy_pass http://127.0.0.1:8081/;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 proxy_cache NAME;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 proxy_cache_valid 1m;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 location /t3.html {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 limit_conn conn 1;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 EOF
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 $t->run();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 # file size is slightly beyond initial window size: 2**16 + 80 bytes
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 $t->write_file('t1.html',
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 join('', map { sprintf "X%04dXXX", $_ } (1 .. 8202)));
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 $t->write_file('t2.html', 'SEE-THIS');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 $t->write_file('t3.html', 'SEE-THIS');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 my %cframe = (
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 2 => \&syn_reply,
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 3 => \&rst_stream,
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 4 => \&settings,
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 6 => \&ping,
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 7 => \&goaway,
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 9 => \&window_update
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 );
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 ###############################################################################
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 # PING
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 my $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 spdy_ping($sess, 0x12345678);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 my $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 my ($frame) = grep { $_->{type} eq "PING" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 ok($frame, 'PING frame');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 is($frame->{value}, 0x12345678, 'PING payload');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 # GET
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 my $sid1 = spdy_stream($sess, { path => '/s' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 ok($frame, 'SYN_REPLAY frame');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 is($frame->{sid}, $sid1, 'SYN_REPLAY stream');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 is($frame->{headers}->{':status'}, 200, 'SYN_REPLAY status');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 is($frame->{headers}->{'x-header'}, 'X-Foo', 'SYN_REPLAY header');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 ok($frame, 'DATA frame');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 is($frame->{length}, length 'body', 'DATA length');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 is($frame->{data}, 'body', 'DATA payload');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 # GET in new SPDY stream in same session
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 my $sid2 = spdy_stream($sess, { path => '/s' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 $frames = spdy_read($sess, all => [{ sid => $sid2, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 is($frame->{sid}, $sid2, 'SYN_REPLAY stream 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 is($frame->{headers}->{':status'}, 200, 'SYN_REPLAY status 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 is($frame->{headers}->{'x-header'}, 'X-Foo', 'SYN_REPLAY header 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 ok($frame, 'DATA frame 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 is($frame->{sid}, $sid2, 'SYN_REPLAY stream 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 is($frame->{length}, length 'body', 'DATA length 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 is($frame->{data}, 'body', 'DATA payload 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 # HEAD
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 $sid1 = spdy_stream($sess, { path => '/s', method => 'HEAD' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 is($frame->{sid}, $sid1, 'SYN_REPLAY stream HEAD');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 is($frame->{headers}->{':status'}, 200, 'SYN_REPLAY status HEAD');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 is($frame->{headers}->{'x-header'}, 'X-Foo', 'SYN_REPLAY header HEAD');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 is($frame, undef, 'HEAD no body');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 # request header
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 $sid1 = spdy_stream($sess, { path => '/t1.html',
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 headers => { "range" => "bytes=10-19" }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180 is($frame->{headers}->{':status'}, 206, 'SYN_REPLAY status range');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 is($frame->{length}, 10, 'DATA length range');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 is($frame->{data}, '002XXXX000', 'DATA payload range');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 # $spdy
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 $sid1 = spdy_stream($sess, { path => '/spdy' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 is($frame->{data}, '3.1', 'spdy variable');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 # spdy_chunk_size=1
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 $sid1 = spdy_stream($sess, { path => '/chunk_size' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201 my @data = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 is(@data, 4, 'chunk_size body chunks');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 is($data[0]->{data}, 'b', 'chunk_size body 1');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 is($data[1]->{data}, 'o', 'chunk_size body 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 is($data[2]->{data}, 'd', 'chunk_size body 3');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206 is($data[3]->{data}, 'y', 'chunk_size body 4');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 # redirect
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211 $sid1 = spdy_stream($sess, { path => '/redirect' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215 is($frame->{headers}->{':status'}, 405, 'SYN_REPLAY status with redirect');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 ok($frame, 'DATA frame with redirect');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 is($frame->{data}, 'body', 'DATA payload with redirect');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 # ensure that HEAD-like requests, i.e., without response body, do not lead to
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222 # client connection close due to cache filling up with upstream response body
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224 TODO: {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225 local $TODO = 'premature client connection close';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html', method => 'HEAD' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 $sid2 = spdy_stream($sess, { path => '/' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 ok(grep ({ $_->{type} eq "SYN_REPLY" } @$frames), 'proxy cache headers only');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 # simple proxy cache test
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 is($frame->{headers}->{':status'}, '200 OK', 'proxy cache unconditional');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245
376
ab2d8abea393 Tests: skip proxy cache conditional test if we didn't get etag.
Sergey Kandaurov <pluknet@nginx.com>
parents: 374
diff changeset
246 my $etag = $frame->{headers}->{'etag'};
ab2d8abea393 Tests: skip proxy cache conditional test if we didn't get etag.
Sergey Kandaurov <pluknet@nginx.com>
parents: 374
diff changeset
247
ab2d8abea393 Tests: skip proxy cache conditional test if we didn't get etag.
Sergey Kandaurov <pluknet@nginx.com>
parents: 374
diff changeset
248 SKIP: {
ab2d8abea393 Tests: skip proxy cache conditional test if we didn't get etag.
Sergey Kandaurov <pluknet@nginx.com>
parents: 374
diff changeset
249 skip 'no etag', 1 unless defined $etag;
374
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 $sid2 = spdy_stream($sess, { path => '/proxy/t2.html',
376
ab2d8abea393 Tests: skip proxy cache conditional test if we didn't get etag.
Sergey Kandaurov <pluknet@nginx.com>
parents: 374
diff changeset
252 headers => { "if-none-match" => $etag }
374
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 $frames = spdy_read($sess, all => [{ sid => $sid2, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 is($frame->{headers}->{':status'}, 304, 'proxy cache conditional');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258
376
ab2d8abea393 Tests: skip proxy cache conditional test if we didn't get etag.
Sergey Kandaurov <pluknet@nginx.com>
parents: 374
diff changeset
259 }
ab2d8abea393 Tests: skip proxy cache conditional test if we didn't get etag.
Sergey Kandaurov <pluknet@nginx.com>
parents: 374
diff changeset
260
374
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261 # request body (uses proxied response)
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html', body => 'TEST' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
267 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268 is($frame->{headers}->{'x-body'}, 'TEST', 'request body');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
269
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
270 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
271 is($frame->{length}, length 'SEE-THIS', 'proxied response length');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272 is($frame->{data}, 'SEE-THIS', 'proxied response');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274 # WINDOW_UPDATE (client side)
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
275
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
276 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
277 $sid1 = spdy_stream($sess, { path => '/t1.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 0 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280 @data = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281 my $sum = eval join '+', map { $_->{length} } @data;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282 is($sum, 2**16, 'iws - stream blocked on initial window size');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 spdy_ping($sess, 0xf00ff00f);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
285 $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
286
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
287 ($frame) = grep { $_->{type} eq "PING" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
288 ok($frame, 'iws - PING not blocked');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 spdy_window($sess, 2**16, $sid1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
291 $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
292 is(@$frames, 0, 'iws - updated stream window');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294 spdy_window($sess, 2**16);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
295 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
296
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
297 @data = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298 $sum = eval join '+', map { $_->{length} } @data;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299 is($sum, 80, 'iws - updated connection window');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301 # SETTINGS (initial window size, client side)
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
302
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
303 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
304 spdy_settings($sess, 7 => 2**17);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
305 spdy_window($sess, 2**17);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
306
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 $sid1 = spdy_stream($sess, { path => '/t1.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 @data = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 $sum = eval join '+', map { $_->{length} } @data;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312 is($sum, 2**16 + 80, 'increased initial window size');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 # probe for negative available space in a flow control window
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 $sid1 = spdy_stream($sess, { path => '/t1.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318 spdy_read($sess, all => [{ sid => $sid1, fin => 0 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320 spdy_window($sess, 1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321 spdy_settings($sess, 7 => 42);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 spdy_window($sess, 1024, $sid1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324 $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325 is(@$frames, 0, 'negative window - no data');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327 spdy_window($sess, 2**16 - 42 - 1024, $sid1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 is(@$frames, 0, 'zero window - no data');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 spdy_window($sess, 1, $sid1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 0 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 is(@$frames, 1, 'positive window - data');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 is(@$frames[0]->{length}, 1, 'positive window - data length');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 # stream multiplexing
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
338 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
339 $sid1 = spdy_stream($sess, { path => '/t1.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 0 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342 @data = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343 $sum = eval join '+', map { $_->{length} } @data;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 is($sum, 2**16, 'multiple - stream1 data');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346 $sid2 = spdy_stream($sess, { path => '/t1.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
347 $frames = spdy_read($sess, all => [{ sid => $sid2, fin => 0 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
348
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
349 @data = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
350 is(@data, 0, 'multiple - stream2 no data');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
351
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352 spdy_window($sess, 2**17, $sid1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
353 spdy_window($sess, 2**17, $sid2);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
354 spdy_window($sess, 2**17);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
355
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
356 $frames = spdy_read($sess, all => [
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
357 { sid => $sid1, fin => 1 },
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
358 { sid => $sid2, fin => 1 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
359 ]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
360
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
361 @data = grep { $_->{type} eq "DATA" && $_->{sid} == $sid1 } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
362 $sum = eval join '+', map { $_->{length} } @data;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
363 is($sum, 80, 'multiple - stream1 remain data');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
364
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
365 @data = grep { $_->{type} eq "DATA" && $_->{sid} == $sid2 } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
366 $sum = eval join '+', map { $_->{length} } @data;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
367 is($sum, 2**16 + 80, 'multiple - stream2 full data');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
368
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
369 # request priority parsing in $spdy_request_priority
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
370
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
371 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
372 $sid1 = spdy_stream($sess, { path => '/prio', prio => 0 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
373 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
374
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
375 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
376 is($frame->{data}, 0, 'priority 0');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
377
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
378 $sid1 = spdy_stream($sess, { path => '/prio', prio => 1 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
379 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
380
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
381 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
382 is($frame->{data}, 1, 'priority 1');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
383
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
384 $sid1 = spdy_stream($sess, { path => '/prio', prio => 7 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
385 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
386
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
387 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
388 is($frame->{data}, 7, 'priority 7');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
389
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
390 # stream muliplexing + priority
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
391
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
392 TODO: {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
393 local $TODO = 'reversed priority' unless $t->has_version('1.5.11');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
394
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
395 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
396 $sid1 = spdy_stream($sess, { path => '/t1.html', prio => 7 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
397 $sid2 = spdy_stream($sess, { path => '/t2.html', prio => 0 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
398 spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
399
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
400 spdy_window($sess, 2**17, $sid1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
401 spdy_window($sess, 2**17, $sid2);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
402 spdy_window($sess, 2**17);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
403
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
404 $frames = spdy_read($sess, all => [
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
405 { sid => $sid1, fin => 1 },
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
406 { sid => $sid2, fin => 1 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
407 ]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
408
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
409 @data = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
410 is(join (' ', map { $_->{sid} } @data), "$sid2 $sid1", 'multiple priority 1');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
411
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
412 # and vice versa
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
413
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
414 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
415 $sid1 = spdy_stream($sess, { path => '/t1.html', prio => 0 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
416 $sid2 = spdy_stream($sess, { path => '/t2.html', prio => 7 });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
417 spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
418
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
419 spdy_window($sess, 2**17, $sid1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
420 spdy_window($sess, 2**17, $sid2);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
421 spdy_window($sess, 2**17);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
422
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
423 $frames = spdy_read($sess, all => [
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
424 { sid => $sid1, fin => 1 },
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
425 { sid => $sid2, fin => 1 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
426 ]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
427
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
428 @data = grep { $_->{type} eq "DATA" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
429 is(join (' ', map { $_->{sid} } @data), "$sid1 $sid2", 'multiple priority 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
430
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
431 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
432
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
433 # limit_conn
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
434
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
435 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
436 spdy_settings($sess, 7 => 1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
437 $sid1 = spdy_stream($sess, { path => '/t3.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
438 $sid2 = spdy_stream($sess, { path => '/t3.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
439 $frames = spdy_read($sess, all => [
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
440 { sid => $sid1, fin => 0 },
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
441 { sid => $sid2, fin => 0 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
442 ]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
443
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
444 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid1 } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
445 is($frame->{headers}->{':status'}, 200, 'conn_limit 1');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
446
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
447 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid2 } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
448 is($frame->{headers}->{':status'}, 503, 'conn_limit 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
449
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
450 # limit_conn + client's RST_STREAM
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
451
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
452 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
453 spdy_settings($sess, 7 => 1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
454 $sid1 = spdy_stream($sess, { path => '/t3.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
455 spdy_rst($sess, $sid1, 5);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
456 $sid2 = spdy_stream($sess, { path => '/t3.html' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
457 $frames = spdy_read($sess, all => [
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
458 { sid => $sid1, fin => 0 },
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
459 { sid => $sid2, fin => 0 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
460 ]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
461
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
462 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid1 } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
463 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 1');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
464
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
465 ($frame) = grep { $_->{type} eq "SYN_REPLY" && $_->{sid} == $sid2 } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
466 is($frame->{headers}->{':status'}, 200, 'RST_STREAM 2');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
467
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
468 # GOAWAY on SYN_STREAM with even StreamID
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
469
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
470 TODO: {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
471 local $TODO = 'not yet';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
472
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
473 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
474 spdy_stream($sess, { path => '/s' }, 2);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
475 $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
476
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
477 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
478 ok($frame, 'even stream - GOAWAY frame');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
479 is($frame->{code}, 1, 'even stream - error code');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
480 is($frame->{sid}, 0, 'even stream - last used stream');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
481
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
482 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
483
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
484 # GOAWAY on SYN_STREAM with backward StreamID
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
485
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
486 TODO: {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
487 local $TODO = 'not yet';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
488
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
489 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
490 $sid1 = spdy_stream($sess, { path => '/s' }, 3);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
491 spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
492
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
493 $sid2 = spdy_stream($sess, { path => '/s' }, 1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
494 $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
495
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
496 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
497 ok($frame, 'backward stream - GOAWAY frame');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
498 is($frame->{code}, 1, 'backward stream - error code');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
499 is($frame->{sid}, $sid1, 'backward stream - last used stream');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
500
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
501 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
502
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
503 # RST_STREAM on the second SYN_STREAM with same StreamID
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
504
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
505 TODO: {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
506 local $TODO = 'not yet';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
507
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
508 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
509 $sid1 = spdy_stream($sess, { path => '/s' }, 3);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
510 spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
511 $sid2 = spdy_stream($sess, { path => '/s' }, 3);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
512 $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
513
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
514 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
515 ok($frame, 'dup stream - RST_STREAM frame');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
516 is($frame->{code}, 1, 'dup stream - error code');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
517 is($frame->{sid}, $sid1, 'dup stream - stream');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
518
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
519 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
520
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
521 # awkward protocol version
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
522
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
523 TODO: {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
524 local $TODO = 'not yet' unless $t->has_version('1.5.11');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
525
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
526 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
527 $sid1 = spdy_stream($sess, { path => '/s', version => 'HTTP/1.10' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
528 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
529
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
530 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
531 is($frame->{headers}->{':status'}, 200, 'awkward version');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
532
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
533 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
534
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
535 # missing mandatory request header
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
536
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
537 $sess = new_session();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
538 $sid1 = spdy_stream($sess, { path => '/s', version => '' });
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
539 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
540
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
541 ($frame) = grep { $_->{type} eq "SYN_REPLY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
542 is($frame->{headers}->{':status'}, 400, 'incomplete headers');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
543
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
544 # GOAWAY before closing a connection by server
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
545
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
546 $t->stop();
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
547
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
548 TODO: {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
549 local $TODO = 'not yet';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
550
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
551 $frames = spdy_read($sess);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
552
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
553 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
554 ok($frame, 'GOAWAY on connection close');
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
555
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
556 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
557
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
558 ###############################################################################
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
559
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
560 sub spdy_ping {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
561 my ($sess, $payload) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
562
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
563 raw_write($sess->{socket}, pack("N3", 0x80030006, 0x4, $payload));
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
564 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
565
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
566 sub spdy_rst {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
567 my ($sess, $sid, $error) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
568
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
569 raw_write($sess->{socket}, pack("N4", 0x80030003, 0x8, $sid, $error));
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
570 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
571
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
572 sub spdy_window {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
573 my ($sess, $win, $stream) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
574
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
575 $stream = 0 unless defined $stream;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
576 raw_write($sess->{socket}, pack("N4", 0x80030009, 8, $stream, $win));
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
577 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
578
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
579 sub spdy_settings {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
580 my ($sess, %extra) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
581
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
582 my $cnt = keys %extra;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
583 my $len = 4 + 8 * $cnt;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
584
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
585 my $buf = pack "N3", 0x80030004, $len, $cnt;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
586 $buf .= join '', map { pack "N2", $_, $extra{$_} } keys %extra;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
587 raw_write($sess->{socket}, $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
588 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
589
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
590 sub spdy_read {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
591 my ($sess, %extra) = @_;
377
ba95a443ff1f Tests: improved spdy test robustness.
Sergey Kandaurov <pluknet@nginx.com>
parents: 376
diff changeset
592 my ($skip, $length, $buf, @got);
ba95a443ff1f Tests: improved spdy test robustness.
Sergey Kandaurov <pluknet@nginx.com>
parents: 376
diff changeset
593 my $tries = 0;
ba95a443ff1f Tests: improved spdy test robustness.
Sergey Kandaurov <pluknet@nginx.com>
parents: 376
diff changeset
594 my $maxtried = 3;
374
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
595
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
596 again:
377
ba95a443ff1f Tests: improved spdy test robustness.
Sergey Kandaurov <pluknet@nginx.com>
parents: 376
diff changeset
597 do {
ba95a443ff1f Tests: improved spdy test robustness.
Sergey Kandaurov <pluknet@nginx.com>
parents: 376
diff changeset
598 $buf = raw_read($sess->{socket});
ba95a443ff1f Tests: improved spdy test robustness.
Sergey Kandaurov <pluknet@nginx.com>
parents: 376
diff changeset
599 } until (defined $buf || $tries++ >= $maxtried);
374
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
600
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
601 for ($skip = 0; $skip < length $buf; $skip += $length + 8) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
602 my $type = unpack("\@$skip B", $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
603 $length = hex unpack("\@$skip x5 H6", $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
604 if ($type == 0) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
605 push @got, dframe($skip, $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
606 test_fin($got[-1], $extra{all});
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
607 next;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
608 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
609
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
610 my $ctype = unpack("\@$skip x2 n", $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
611 push @got, $cframe{$ctype}($sess, $skip, $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
612 test_fin($got[-1], $extra{all});
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
613 }
377
ba95a443ff1f Tests: improved spdy test robustness.
Sergey Kandaurov <pluknet@nginx.com>
parents: 376
diff changeset
614 goto again if %extra && @{$extra{all}} && $tries < $maxtried;
374
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
615 return \@got;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
616 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
617
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
618 sub test_fin {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
619 my ($frame, $all) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
620
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
621 @{$all} = grep {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
622 !($_->{sid} == $frame->{sid} && $_->{fin} == $frame->{fin})
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
623 } @{$all} if defined $frame->{fin};
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
624 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
625
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
626 sub dframe {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
627 my ($skip, $buf) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
628 my %frame;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
629
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
630 my $stream = unpack "\@$skip B32", $buf; $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
631 substr($stream, 0, 1) = 0;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
632 $stream = unpack("N", pack("B32", $stream));
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
633 $frame{sid} = $stream;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
634
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
635 my $flags = unpack "\@$skip B8", $buf; $skip += 1;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
636 $frame{fin} = substr($flags, 7, 1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
637
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
638 my $length = hex (unpack "\@$skip H6", $buf); $skip += 3;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
639 $frame{length} = $length;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
640
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
641 $frame{data} = substr($buf, $skip, $length);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
642 $frame{type} = "DATA";
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
643 return \%frame;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
644 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
645
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
646 sub spdy_stream {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
647 my ($ctx, $uri, $stream) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
648 my ($input, $output, $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
649 my ($d, $status);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
650
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
651 my $host = $uri->{host} || '127.0.0.1:8080';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
652 my $method = $uri->{method} || 'GET';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
653 my $headers = $uri->{headers} || {};
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
654 my $body = $uri->{body};
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
655 my $prio = defined $uri->{prio} ? $uri->{prio} : 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
656 my $version = defined $uri->{version} ? $uri->{version} : "HTTP/1.1";
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
657
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
658 if ($stream) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
659 $ctx->{last_stream} = $stream;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
660 } else {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
661 $ctx->{last_stream} += 2;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
662 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
663
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
664 $buf = pack("NC", 0x80030001, not $body);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
665 $buf .= pack("xxx"); # Length stub
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
666 $buf .= pack("N", $ctx->{last_stream}); # Stream-ID
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
667 $buf .= pack("N", 0); # Assoc. Stream-ID
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
668 $buf .= pack("n", $prio << 13);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
669
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
670 my $ent = 4 + keys %{$headers};
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
671 $ent++ if $body;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
672 $ent++ if $version;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
673
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
674 $input = pack("N", $ent);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
675 $input .= hpack(":host", $host);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
676 $input .= hpack(":method", $method);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
677 $input .= hpack(":path", $uri->{path});
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
678 $input .= hpack(":scheme", "http");
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
679 if ($version) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
680 $input .= hpack(":version", $version);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
681 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
682 if ($body) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
683 $input .= hpack("content-length", length $body);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
684 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
685 $input .= join '', map { hpack($_, $headers->{$_}) } keys %{$headers};
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
686
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
687 $d = $ctx->{zlib}->{d};
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
688 $status = $d->deflate($input => \my $start);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
689 $status == Compress::Raw::Zlib->Z_OK or fail "deflate failed";
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
690 $status = $d->flush(\my $tail => Compress::Raw::Zlib->Z_SYNC_FLUSH);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
691 $status == Compress::Raw::Zlib->Z_OK or fail "flush failed";
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
692 $output = $start . $tail;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
693
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
694 my $len = '';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
695 vec($len, 7, 8) = (length $output) + 10;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
696 $buf |= $len;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
697 $buf .= $output;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
698
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
699 if (defined $body) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
700 $buf .= pack "NCxn", $ctx->{last_stream}, 0x01, length $body;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
701 $buf .= $body;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
702 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
703
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
704 raw_write($ctx->{socket}, $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
705 return $ctx->{last_stream};
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
706 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
707
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
708 sub syn_reply {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
709 my ($ctx, $skip, $buf) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
710 my ($i, $status);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
711 my %payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
712
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
713 $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
714 my $flags = unpack "\@$skip B8", $buf; $skip += 1;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
715 $payload{fin} = substr($flags, 7, 1);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
716
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
717 my $length = hex unpack "\@$skip H6", $buf; $skip += 3;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
718 $payload{length} = $length;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
719 $payload{type} = 'SYN_REPLY';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
720
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
721 my $stream = unpack "\@$skip B32", $buf; $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
722 substr($stream, 0, 1) = 0;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
723 $stream = unpack("N", pack("B32", $stream));
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
724 $payload{sid} = $stream;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
725
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
726 my $input = substr($buf, $skip, $length - 4);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
727 $i = $ctx->{zlib}->{i};
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
728
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
729 $status = $i->inflate($input => \my $out);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
730 fail "Failed: $status" unless $status == Compress::Raw::Zlib->Z_OK;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
731 $payload{headers} = hunpack($out);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
732 return \%payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
733 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
734
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
735 sub rst_stream {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
736 my ($ctx, $skip, $buf) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
737 my %payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
738
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
739 $skip += 5;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
740 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
741 $payload{type} = 'RST_STREAM';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
742 $payload{sid} = unpack "\@$skip N", $buf; $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
743 $payload{code} = unpack "\@$skip N", $buf;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
744 return \%payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
745 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
746
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
747 sub settings {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
748 my ($ctx, $skip, $buf) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
749 my %payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
750
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
751 $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
752 $payload{flags} = unpack "\@$skip H", $buf; $skip += 1;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
753 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
754 $payload{type} = 'SETTINGS';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
755
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
756 my $nent = unpack "\@$skip N", $buf; $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
757 for (1 .. $nent) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
758 my $flags = hex unpack "\@$skip H2", $buf; $skip += 1;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
759 my $id = hex unpack "\@$skip H6", $buf; $skip += 3;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
760 $payload{$id}{flags} = $flags;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
761 $payload{$id}{value} = unpack "\@$skip N", $buf; $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
762 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
763 return \%payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
764 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
765
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
766 sub ping {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
767 my ($ctx, $skip, $buf) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
768 my %payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
769
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
770 $skip += 5;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
771 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
772 $payload{type} = 'PING';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
773 $payload{value} = unpack "\@$skip N", $buf;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
774 return \%payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
775 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
776
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
777 sub goaway {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
778 my ($ctx, $skip, $buf) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
779 my %payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
780
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
781 $skip += 5;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
782 $payload{length} = hex unpack "\@$skip H6", $buf; $skip += 3;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
783 $payload{type} = 'GOAWAY';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
784 $payload{sid} = unpack "\@$skip N", $buf; $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
785 $payload{code} = unpack "\@$skip N", $buf;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
786 return \%payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
787 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
788
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
789 sub window_update {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
790 my ($ctx, $skip, $buf) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
791 my %payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
792
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
793 $skip += 5;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
794
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
795 $payload{length} = hex(unpack "\@$skip H6", $buf); $skip += 3;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
796 $payload{type} = 'WINDOW_UPDATE';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
797
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
798 my $stream = unpack "\@$skip B32", $buf; $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
799 substr($stream, 0, 1) = 0;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
800 $stream = unpack("N", pack("B32", $stream));
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
801 $payload{sid} = $stream;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
802
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
803 my $value = unpack "\@$skip B32", $buf;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
804 substr($value, 0, 1) = 0;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
805 $payload{wdelta} = unpack("N", pack("B32", $value));
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
806 return \%payload;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
807 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
808
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
809 sub hpack {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
810 my ($name, $value) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
811
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
812 pack("N", length($name)) . $name . pack("N", length($value)) . $value;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
813 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
814
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
815 sub hunpack {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
816 my ($data) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
817 my %headers;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
818 my $skip = 0;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
819
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
820 my $nent = unpack "\@$skip N", $data; $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
821 for (1 .. $nent) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
822 my $len = unpack("\@$skip N", $data); $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
823 my $name = unpack("\@$skip A$len", $data); $skip += $len;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
824
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
825 $len = unpack("\@$skip N", $data); $skip += 4;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
826 my $value = unpack("\@$skip A$len", $data); $skip += $len;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
827
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
828 $headers{$name} = $value;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
829 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
830 return \%headers;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
831 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
832
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
833 sub raw_read {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
834 my ($s) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
835 my ($got, $buf);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
836
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
837 $s->blocking(0);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
838 while (IO::Select->new($s)->can_read(0.4)) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
839 my $n = $s->sysread($buf, 1024);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
840 last unless $n;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
841 $got .= $buf;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
842 };
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
843 log_in($got);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
844 return $got;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
845 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
846
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
847 sub raw_write {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
848 my ($s, $message) = @_;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
849
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
850 local $SIG{PIPE} = 'IGNORE';
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
851
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
852 $s->blocking(0);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
853 while (IO::Select->new($s)->can_write(0.4)) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
854 log_out($message);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
855 my $n = $s->syswrite($message);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
856 last unless $n;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
857 $message = substr($message, $n);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
858 last unless length $message;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
859 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
860 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
861
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
862 sub new_session {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
863 my ($d, $i, $status);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
864
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
865 ($d, $status) = Compress::Raw::Zlib::Deflate->new(
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
866 -WindowBits => 12,
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
867 -Dictionary => dictionary(),
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
868 -Level => Compress::Raw::Zlib->Z_NO_COMPRESSION
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
869 );
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
870 fail "Zlib failure: $status" unless $d;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
871
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
872 ($i, $status) = Compress::Raw::Zlib::Inflate->new(
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
873 -WindowBits => Compress::Raw::Zlib->WANT_GZIP_OR_ZLIB,
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
874 -Dictionary => dictionary()
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
875 );
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
876 fail "Zlib failure: $status" unless $i;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
877
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
878 return { zlib => { i => $i, d => $d },
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
879 socket => new_socket(), last_stream => -1 };
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
880 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
881
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
882 sub new_socket {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
883 my $s;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
884
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
885 eval {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
886 local $SIG{ALRM} = sub { die "timeout\n" };
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
887 local $SIG{PIPE} = sub { die "sigpipe\n" };
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
888 alarm(2);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
889 $s = IO::Socket::INET->new(
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
890 Proto => 'tcp',
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
891 PeerAddr => '127.0.0.1:8080',
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
892 );
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
893 alarm(0);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
894 };
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
895 alarm(0);
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
896
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
897 if ($@) {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
898 log_in("died: $@");
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
899 return undef;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
900 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
901
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
902 return $s;
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
903 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
904
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
905 sub dictionary {
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
906 join('', (map pack('N/a*', $_), qw(
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
907 options
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
908 head
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
909 post
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
910 put
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
911 delete
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
912 trace
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
913 accept
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
914 accept-charset
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
915 accept-encoding
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
916 accept-language
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
917 accept-ranges
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
918 age
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
919 allow
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
920 authorization
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
921 cache-control
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
922 connection
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
923 content-base
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
924 content-encoding
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
925 content-language
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
926 content-length
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
927 content-location
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
928 content-md5
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
929 content-range
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
930 content-type
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
931 date
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
932 etag
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
933 expect
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
934 expires
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
935 from
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
936 host
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
937 if-match
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
938 if-modified-since
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
939 if-none-match
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
940 if-range
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
941 if-unmodified-since
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
942 last-modified
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
943 location
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
944 max-forwards
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
945 pragma
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
946 proxy-authenticate
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
947 proxy-authorization
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
948 range
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
949 referer
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
950 retry-after
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
951 server
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
952 te
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
953 trailer
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
954 transfer-encoding
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
955 upgrade
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
956 user-agent
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
957 vary
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
958 via
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
959 warning
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
960 www-authenticate
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
961 method
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
962 get
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
963 status), "200 OK",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
964 qw(version HTTP/1.1 url public set-cookie keep-alive origin)),
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
965 "100101201202205206300302303304305306307402405406407408409410",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
966 "411412413414415416417502504505",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
967 "203 Non-Authoritative Information",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
968 "204 No Content",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
969 "301 Moved Permanently",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
970 "400 Bad Request",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
971 "401 Unauthorized",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
972 "403 Forbidden",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
973 "404 Not Found",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
974 "500 Internal Server Error",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
975 "501 Not Implemented",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
976 "503 Service Unavailable",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
977 "Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
978 " 00:00:00",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
979 " Mon, Tue, Wed, Thu, Fri, Sat, Sun, GMT",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
980 "chunked,text/html,image/png,image/jpg,image/gif,",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
981 "application/xml,application/xhtml+xml,text/plain,",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
982 "text/javascript,public", "privatemax-age=gzip,deflate,",
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
983 "sdchcharset=utf-8charset=iso-8859-1,utf-,*,enq=0."
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
984 );
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
985 }
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
986
ac804fd1eb56 Tests: basic SPDY tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
987 ###############################################################################