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