File Coverage

blib/lib/Protocol/SPDY/Constants.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1             package Protocol::SPDY::Constants;
2             $Protocol::SPDY::Constants::VERSION = '1.001';
3 6     6   34554 use strict;
  6         8  
  6         200  
4 6     6   23 use warnings;
  6         6  
  6         150  
5 6     6   2438 use parent qw(Exporter);
  6         1403  
  6         27  
6              
7             =head1 NAME
8              
9             Protocol::SPDY::Constants - constant definitions for the SPDY protocol
10              
11             =head1 VERSION
12              
13             version 1.001
14              
15             =head1 SYNOPSIS
16              
17             use Protocol::SPDY::Constants ':all';
18              
19             =head1 DESCRIPTION
20              
21             Provides some constants.
22              
23             =head1 CONSTANTS
24              
25             =head2 FLAG_FIN
26              
27             Value for the FIN flag in control/data frames.
28              
29             =head2 FLAG_COMPRESS
30              
31             Compression flag - currently unused
32              
33             =head2 FLAG_UNI
34              
35             Unidirectional flag - used to mark a stream as not requiring a reply.
36              
37             =head2 HEADER_LENGTH
38              
39             Number of bytes required in order to work out how big a frame will be.
40              
41             =head2 ZLIB_DICTIONARY
42              
43             Initial compression dictionary for the zlib compression protocol used
44             for name/value pair data.
45              
46             =head2 MAX_SUPPORTED_VERSION
47              
48             Highest version we know about.
49              
50             =head1 RST_STREAM CODES
51              
52             The following codes can be returned as values in a
53             L frame. See
54             the L
55             and L
56             methods.
57              
58             =head2 PROTOCOL_ERROR
59              
60             There was a protocol violation in something we've sent to the other side.
61              
62             =head2 INVALID_STREAM
63              
64             The requested stream is not valid (for example, when we receive a reply
65             to a stream that we did not initiate).
66              
67             =head2 REFUSED_STREAM
68              
69             We do not want this stream.
70              
71             =head2 UNSUPPORTED_VERSION
72              
73             The protocol version requested is not supported by this library.
74              
75             =head2 CANCEL
76              
77             Used by the initiator to stop an active stream before normal completion.
78              
79             =head2 INTERNAL_ERROR
80              
81             Generic error when internal state is invalid.
82              
83             =head2 FLOW_CONTROL_ERROR
84              
85             We violated the expected window update behaviour.
86              
87             =cut
88              
89             use constant {
90             # Flag indicating whether this is the final packet in the stream
91 6         1886 FLAG_FIN => 0x01,
92             # Whether compression is enabled
93             FLAG_COMPRESS => 0x02,
94             # Unidirectional (section 2.3.6)
95             FLAG_UNI => 0x02,
96             # Number of bytes in the header (common between control and data frames)
97             HEADER_LENGTH => 8,
98             # The spec requires seeding our zlib instance with a specific dictionary to get
99             # better performance. Note that the dictionary varies depending on the version
100             # of the protocol we're dealing with - this is the spdy/3.1 dictionary:
101             ZLIB_DICTIONARY => join('',
102             (
103             # These are all length-prefixed strings, mostly client=>server traffic
104             map pack('N/a*', $_), qw(
105             options
106             head
107             post
108             put
109             delete
110             trace
111             accept
112             accept-charset
113             accept-encoding
114             accept-language
115             accept-ranges
116             age
117             allow
118             authorization
119             cache-control
120             connection
121             content-base
122             content-encoding
123             content-language
124             content-length
125             content-location
126             content-md5
127             content-range
128             content-type
129             date
130             etag
131             expect
132             expires
133             from
134             host
135             if-match
136             if-modified-since
137             if-none-match
138             if-range
139             if-unmodified-since
140             last-modified
141             location
142             max-forwards
143             pragma
144             proxy-authenticate
145             proxy-authorization
146             range
147             referer
148             retry-after
149             server
150             te
151             trailer
152             transfer-encoding
153             upgrade
154             user-agent
155             vary
156             via
157             warning
158             www-authenticate
159             method
160             get
161             status
162             ),
163             "200 OK",
164             qw(
165             version
166             HTTP/1.1
167             url
168             public
169             set-cookie
170             keep-alive
171             origin
172             )
173             ),
174             # Now we have some other useful strings - these are mostly server responses, no length prefix
175             "100101201202205206300302303304305306307402405406407408409410411412413414415416417502504505",
176             "203 Non-Authoritative Information",
177             "204 No Content",
178             "301 Moved Permanently",
179             "400 Bad Request",
180             "401 Unauthorized",
181             "403 Forbidden",
182             "404 Not Found",
183             "500 Internal Server Error",
184             "501 Not Implemented",
185             "503 Service Unavailable",
186             "Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec",
187             " 00:00:00",
188             " Mon, Tue, Wed, Thu, Fri, Sat, Sun, GMT",
189             "chunked,text/html,image/png,image/jpg,image/gif,application/xml,application/xhtml+xml,text/plain,text/javascript,public",
190             "privatemax-age=gzip,deflate,sdchcharset=utf-8charset=iso-8859-1,utf-,*,enq=0.",
191             ),
192              
193             # Which version we support
194             MAX_SUPPORTED_VERSION => 3,
195             # SETTINGS packet flags
196             # Request to persist settings
197             FLAG_SETTINGS_PERSIST_VALUE => 0x01,
198             # Inform other side of previously-persisted settings
199             FLAG_SETTINGS_PERSISTED => 0x02,
200             # Status codes for RST_STREAM
201             PROTOCOL_ERROR => 1,
202             INVALID_STREAM => 2,
203             REFUSED_STREAM => 3,
204             UNSUPPORTED_VERSION => 4,
205             CANCEL => 5,
206             INTERNAL_ERROR => 6,
207             FLOW_CONTROL_ERROR => 7,
208              
209             FRAME_TYPE_BY_ID => {
210             1 => 'SYN_STREAM',
211             2 => 'SYN_REPLY',
212             3 => 'RST_STREAM',
213             4 => 'SETTINGS',
214             5 => 'NOOP',
215             6 => 'PING',
216             7 => 'GOAWAY',
217             8 => 'HEADERS',
218             9 => 'WINDOW_UPDATE',
219             10 => 'CREDENTIAL', # no longer present in 3.1+
220             },
221             SETTINGS_BY_ID => {
222             # Expected upload bandwidth
223             1 => 'EXPECTED_UPLOAD_BANDWIDTH',
224             # Expected download bandwidth
225             2 => 'EXPECTED_DOWNLOAD_BANDWIDTH',
226             # How long we expect packets to take to go from here to there and back again
227             3 => 'EXPECTED_ROUND_TRIP_TIME',
228             # How many streams we want - clients which do not want server push seem to
229             # use a 0 value here to disable the feature
230             4 => 'MAX_CONCURRENT_STREAMS',
231             # TCP initial client window size
232             5 => 'CURRENT_CWND',
233             # Retransmission rate on downloads (percentage)
234             6 => 'DOWNLOAD_RETRANS_RATE',
235             # Start with windows of this size (in bytes)
236             7 => 'INITIAL_WINDOW_SIZE',
237             },
238             RST_STATUS_CODE_BY_ID => {
239             1 => 'PROTOCOL_ERROR',
240             2 => 'INVALID_STREAM',
241             3 => 'REFUSED_STREAM',
242             4 => 'UNSUPPORTED_VERSION',
243             5 => 'CANCEL',
244             6 => 'INTERNAL_ERROR',
245             7 => 'FLOW_CONTROL_ERROR',
246             8 => 'STREAM_IN_USE',
247             9 => 'STREAM_ALREADY_CLOSED',
248             10 => 'INVALID_CREDENTIALS',
249             11 => 'FRAME_TOO_LARGE',
250             },
251 6     6   1265 };
  6         10  
252              
253             # Reversed lookup mappings
254             use constant {
255 6         57 FRAME_TYPE_BY_NAME => +{ reverse %{+FRAME_TYPE_BY_ID} },
  6         43  
256 6         733 SETTINGS_BY_NAME => +{ reverse %{+SETTINGS_BY_ID} },
257 6         8 RST_STATUS_CODE_BY_NAME => +{ reverse %{+RST_STATUS_CODE_BY_ID} },
258 6     6   29 };
  6         7  
259              
260             our @EXPORT_OK = qw(
261             FLAG_FIN FLAG_COMPRESS FLAG_UNI
262             FRAME_TYPE_BY_ID FRAME_TYPE_BY_NAME
263             SETTINGS_BY_ID SETTINGS_BY_NAME
264             FLAG_SETTINGS_PERSISTED FLAG_SETTINGS_PERSIST_VALUE
265             RST_STATUS_CODE_BY_ID RST_STATUS_CODE_BY_NAME
266             HEADER_LENGTH
267             ZLIB_DICTIONARY MAX_SUPPORTED_VERSION
268             PROTOCOL_ERROR INVALID_STREAM REFUSED_STREAM UNSUPPORTED_VERSION
269             CANCEL INTERNAL_ERROR FLOW_CONTROL_ERROR
270             );
271              
272             our %EXPORT_TAGS = (
273             'all' => \@EXPORT_OK,
274             );
275              
276             1;
277              
278             __END__