Implement HasPermission() method in PermissionService.
[chromium-blink-merge.git] / net / spdy / spdy_protocol.h
blob112e9289874903bc638f6b8017556060ff0accec
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file contains some protocol structures for use with SPDY 2 and 3
6 // The SPDY 2 spec can be found at:
7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft2
8 // The SPDY 3 spec can be found at:
9 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3
11 #ifndef NET_SPDY_SPDY_PROTOCOL_H_
12 #define NET_SPDY_SPDY_PROTOCOL_H_
14 #include <limits>
15 #include <map>
16 #include <string>
17 #include <vector>
19 #include "base/basictypes.h"
20 #include "base/compiler_specific.h"
21 #include "base/logging.h"
22 #include "base/memory/scoped_ptr.h"
23 #include "base/strings/string_piece.h"
24 #include "base/sys_byteorder.h"
25 #include "net/base/net_export.h"
26 #include "net/spdy/spdy_bitmasks.h"
28 namespace net {
30 // The major versions of SPDY. Major version differences indicate
31 // framer-layer incompatibility, as opposed to minor version numbers
32 // which indicate application-layer incompatibility. Do not rely on
33 // the mapping from enum value SPDYn to the integer n.
34 enum SpdyMajorVersion {
35 SPDY2 = 2,
36 SPDY_MIN_VERSION = SPDY2,
37 SPDY3 = 3,
38 SPDY4 = 4,
39 SPDY5 = 5,
40 SPDY_MAX_VERSION = SPDY5
43 // A SPDY stream id is a 31 bit entity.
44 typedef uint32 SpdyStreamId;
46 // Specifies the stream ID used to denote the current session (for
47 // flow control).
48 const SpdyStreamId kSessionFlowControlStreamId = 0;
50 // Initial window size for a Spdy stream in bytes.
51 const int32 kSpdyStreamInitialWindowSize = 64 * 1024; // 64 KBytes
53 // The maxmium possible control frame size allowed by the spec.
54 const int32 kSpdyMaxControlFrameSize = (1 << 24) - 1;
56 // The maximum control frame size we accept.
57 const int32 kControlFrameSizeLimit = 1 << 14;
59 // Initial window size for a Spdy session in bytes.
60 const int32 kSpdySessionInitialWindowSize = 64 * 1024; // 64 KBytes
62 // Maximum window size for a Spdy stream or session.
63 const int32 kSpdyMaximumWindowSize = 0x7FFFFFFF; // Max signed 32bit int
65 // Maximum padding size in octets for one DATA or HEADERS or PUSH_PROMISE frame.
66 const int32 kPaddingSizePerFrame = 256;
68 // SPDY 2 dictionary.
69 // This is just a hacked dictionary to use for shrinking HTTP-like headers.
70 const char kV2Dictionary[] =
71 "optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-"
72 "languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi"
73 "f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser"
74 "-agent10010120020120220320420520630030130230330430530630740040140240340440"
75 "5406407408409410411412413414415416417500501502503504505accept-rangesageeta"
76 "glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic"
77 "ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran"
78 "sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati"
79 "oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo"
80 "ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe"
81 "pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic"
82 "ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1"
83 ".1statusversionurl";
84 const int kV2DictionarySize = arraysize(kV2Dictionary);
86 // SPDY 3 dictionary.
87 const char kV3Dictionary[] = {
88 0x00, 0x00, 0x00, 0x07, 0x6f, 0x70, 0x74, 0x69, // ....opti
89 0x6f, 0x6e, 0x73, 0x00, 0x00, 0x00, 0x04, 0x68, // ons....h
90 0x65, 0x61, 0x64, 0x00, 0x00, 0x00, 0x04, 0x70, // ead....p
91 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x03, 0x70, // ost....p
92 0x75, 0x74, 0x00, 0x00, 0x00, 0x06, 0x64, 0x65, // ut....de
93 0x6c, 0x65, 0x74, 0x65, 0x00, 0x00, 0x00, 0x05, // lete....
94 0x74, 0x72, 0x61, 0x63, 0x65, 0x00, 0x00, 0x00, // trace...
95 0x06, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x00, // .accept.
96 0x00, 0x00, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70, // ...accep
97 0x74, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // t-charse
98 0x74, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x63, 0x63, // t....acc
99 0x65, 0x70, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // ept-enco
100 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x0f, // ding....
101 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x6c, // accept-l
102 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x00, // anguage.
103 0x00, 0x00, 0x0d, 0x61, 0x63, 0x63, 0x65, 0x70, // ...accep
104 0x74, 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x73, // t-ranges
105 0x00, 0x00, 0x00, 0x03, 0x61, 0x67, 0x65, 0x00, // ....age.
106 0x00, 0x00, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, // ...allow
107 0x00, 0x00, 0x00, 0x0d, 0x61, 0x75, 0x74, 0x68, // ....auth
108 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, // orizatio
109 0x6e, 0x00, 0x00, 0x00, 0x0d, 0x63, 0x61, 0x63, // n....cac
110 0x68, 0x65, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, // he-contr
111 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, // ol....co
112 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, // nnection
113 0x00, 0x00, 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, // ....cont
114 0x65, 0x6e, 0x74, 0x2d, 0x62, 0x61, 0x73, 0x65, // ent-base
115 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, 0x6e, 0x74, // ....cont
116 0x65, 0x6e, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // ent-enco
117 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, // ding....
118 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, // content-
119 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, // language
120 0x00, 0x00, 0x00, 0x0e, 0x63, 0x6f, 0x6e, 0x74, // ....cont
121 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x65, 0x6e, 0x67, // ent-leng
122 0x74, 0x68, 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, // th....co
123 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x6f, // ntent-lo
124 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, // cation..
125 0x00, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // ..conten
126 0x74, 0x2d, 0x6d, 0x64, 0x35, 0x00, 0x00, 0x00, // t-md5...
127 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, // .content
128 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, // -range..
129 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // ..conten
130 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00, // t-type..
131 0x00, 0x04, 0x64, 0x61, 0x74, 0x65, 0x00, 0x00, // ..date..
132 0x00, 0x04, 0x65, 0x74, 0x61, 0x67, 0x00, 0x00, // ..etag..
133 0x00, 0x06, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, // ..expect
134 0x00, 0x00, 0x00, 0x07, 0x65, 0x78, 0x70, 0x69, // ....expi
135 0x72, 0x65, 0x73, 0x00, 0x00, 0x00, 0x04, 0x66, // res....f
136 0x72, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x04, 0x68, // rom....h
137 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x08, 0x69, // ost....i
138 0x66, 0x2d, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, // f-match.
139 0x00, 0x00, 0x11, 0x69, 0x66, 0x2d, 0x6d, 0x6f, // ...if-mo
140 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x2d, 0x73, // dified-s
141 0x69, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x0d, // ince....
142 0x69, 0x66, 0x2d, 0x6e, 0x6f, 0x6e, 0x65, 0x2d, // if-none-
143 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, 0x00, 0x00, // match...
144 0x08, 0x69, 0x66, 0x2d, 0x72, 0x61, 0x6e, 0x67, // .if-rang
145 0x65, 0x00, 0x00, 0x00, 0x13, 0x69, 0x66, 0x2d, // e....if-
146 0x75, 0x6e, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, // unmodifi
147 0x65, 0x64, 0x2d, 0x73, 0x69, 0x6e, 0x63, 0x65, // ed-since
148 0x00, 0x00, 0x00, 0x0d, 0x6c, 0x61, 0x73, 0x74, // ....last
149 0x2d, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, // -modifie
150 0x64, 0x00, 0x00, 0x00, 0x08, 0x6c, 0x6f, 0x63, // d....loc
151 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, // ation...
152 0x0c, 0x6d, 0x61, 0x78, 0x2d, 0x66, 0x6f, 0x72, // .max-for
153 0x77, 0x61, 0x72, 0x64, 0x73, 0x00, 0x00, 0x00, // wards...
154 0x06, 0x70, 0x72, 0x61, 0x67, 0x6d, 0x61, 0x00, // .pragma.
155 0x00, 0x00, 0x12, 0x70, 0x72, 0x6f, 0x78, 0x79, // ...proxy
156 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, // -authent
157 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, // icate...
158 0x13, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2d, 0x61, // .proxy-a
159 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, // uthoriza
160 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, // tion....
161 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, 0x00, // range...
162 0x07, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, // .referer
163 0x00, 0x00, 0x00, 0x0b, 0x72, 0x65, 0x74, 0x72, // ....retr
164 0x79, 0x2d, 0x61, 0x66, 0x74, 0x65, 0x72, 0x00, // y-after.
165 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, // ...serve
166 0x72, 0x00, 0x00, 0x00, 0x02, 0x74, 0x65, 0x00, // r....te.
167 0x00, 0x00, 0x07, 0x74, 0x72, 0x61, 0x69, 0x6c, // ...trail
168 0x65, 0x72, 0x00, 0x00, 0x00, 0x11, 0x74, 0x72, // er....tr
169 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x2d, 0x65, // ansfer-e
170 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x00, // ncoding.
171 0x00, 0x00, 0x07, 0x75, 0x70, 0x67, 0x72, 0x61, // ...upgra
172 0x64, 0x65, 0x00, 0x00, 0x00, 0x0a, 0x75, 0x73, // de....us
173 0x65, 0x72, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74, // er-agent
174 0x00, 0x00, 0x00, 0x04, 0x76, 0x61, 0x72, 0x79, // ....vary
175 0x00, 0x00, 0x00, 0x03, 0x76, 0x69, 0x61, 0x00, // ....via.
176 0x00, 0x00, 0x07, 0x77, 0x61, 0x72, 0x6e, 0x69, // ...warni
177 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, 0x77, 0x77, // ng....ww
178 0x77, 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, // w-authen
179 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, // ticate..
180 0x00, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, // ..method
181 0x00, 0x00, 0x00, 0x03, 0x67, 0x65, 0x74, 0x00, // ....get.
182 0x00, 0x00, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, // ...statu
183 0x73, 0x00, 0x00, 0x00, 0x06, 0x32, 0x30, 0x30, // s....200
184 0x20, 0x4f, 0x4b, 0x00, 0x00, 0x00, 0x07, 0x76, // .OK....v
185 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, 0x00, // ersion..
186 0x00, 0x08, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, // ..HTTP.1
187 0x2e, 0x31, 0x00, 0x00, 0x00, 0x03, 0x75, 0x72, // .1....ur
188 0x6c, 0x00, 0x00, 0x00, 0x06, 0x70, 0x75, 0x62, // l....pub
189 0x6c, 0x69, 0x63, 0x00, 0x00, 0x00, 0x0a, 0x73, // lic....s
190 0x65, 0x74, 0x2d, 0x63, 0x6f, 0x6f, 0x6b, 0x69, // et-cooki
191 0x65, 0x00, 0x00, 0x00, 0x0a, 0x6b, 0x65, 0x65, // e....kee
192 0x70, 0x2d, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x00, // p-alive.
193 0x00, 0x00, 0x06, 0x6f, 0x72, 0x69, 0x67, 0x69, // ...origi
194 0x6e, 0x31, 0x30, 0x30, 0x31, 0x30, 0x31, 0x32, // n1001012
195 0x30, 0x31, 0x32, 0x30, 0x32, 0x32, 0x30, 0x35, // 01202205
196 0x32, 0x30, 0x36, 0x33, 0x30, 0x30, 0x33, 0x30, // 20630030
197 0x32, 0x33, 0x30, 0x33, 0x33, 0x30, 0x34, 0x33, // 23033043
198 0x30, 0x35, 0x33, 0x30, 0x36, 0x33, 0x30, 0x37, // 05306307
199 0x34, 0x30, 0x32, 0x34, 0x30, 0x35, 0x34, 0x30, // 40240540
200 0x36, 0x34, 0x30, 0x37, 0x34, 0x30, 0x38, 0x34, // 64074084
201 0x30, 0x39, 0x34, 0x31, 0x30, 0x34, 0x31, 0x31, // 09410411
202 0x34, 0x31, 0x32, 0x34, 0x31, 0x33, 0x34, 0x31, // 41241341
203 0x34, 0x34, 0x31, 0x35, 0x34, 0x31, 0x36, 0x34, // 44154164
204 0x31, 0x37, 0x35, 0x30, 0x32, 0x35, 0x30, 0x34, // 17502504
205 0x35, 0x30, 0x35, 0x32, 0x30, 0x33, 0x20, 0x4e, // 505203.N
206 0x6f, 0x6e, 0x2d, 0x41, 0x75, 0x74, 0x68, 0x6f, // on-Autho
207 0x72, 0x69, 0x74, 0x61, 0x74, 0x69, 0x76, 0x65, // ritative
208 0x20, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, // .Informa
209 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x30, 0x34, 0x20, // tion204.
210 0x4e, 0x6f, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x65, // No.Conte
211 0x6e, 0x74, 0x33, 0x30, 0x31, 0x20, 0x4d, 0x6f, // nt301.Mo
212 0x76, 0x65, 0x64, 0x20, 0x50, 0x65, 0x72, 0x6d, // ved.Perm
213 0x61, 0x6e, 0x65, 0x6e, 0x74, 0x6c, 0x79, 0x34, // anently4
214 0x30, 0x30, 0x20, 0x42, 0x61, 0x64, 0x20, 0x52, // 00.Bad.R
215 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x34, 0x30, // equest40
216 0x31, 0x20, 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68, // 1.Unauth
217 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64, 0x34, 0x30, // orized40
218 0x33, 0x20, 0x46, 0x6f, 0x72, 0x62, 0x69, 0x64, // 3.Forbid
219 0x64, 0x65, 0x6e, 0x34, 0x30, 0x34, 0x20, 0x4e, // den404.N
220 0x6f, 0x74, 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, // ot.Found
221 0x35, 0x30, 0x30, 0x20, 0x49, 0x6e, 0x74, 0x65, // 500.Inte
222 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x53, 0x65, 0x72, // rnal.Ser
223 0x76, 0x65, 0x72, 0x20, 0x45, 0x72, 0x72, 0x6f, // ver.Erro
224 0x72, 0x35, 0x30, 0x31, 0x20, 0x4e, 0x6f, 0x74, // r501.Not
225 0x20, 0x49, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, // .Impleme
226 0x6e, 0x74, 0x65, 0x64, 0x35, 0x30, 0x33, 0x20, // nted503.
227 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, // Service.
228 0x55, 0x6e, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, // Unavaila
229 0x62, 0x6c, 0x65, 0x4a, 0x61, 0x6e, 0x20, 0x46, // bleJan.F
230 0x65, 0x62, 0x20, 0x4d, 0x61, 0x72, 0x20, 0x41, // eb.Mar.A
231 0x70, 0x72, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x4a, // pr.May.J
232 0x75, 0x6e, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x41, // un.Jul.A
233 0x75, 0x67, 0x20, 0x53, 0x65, 0x70, 0x74, 0x20, // ug.Sept.
234 0x4f, 0x63, 0x74, 0x20, 0x4e, 0x6f, 0x76, 0x20, // Oct.Nov.
235 0x44, 0x65, 0x63, 0x20, 0x30, 0x30, 0x3a, 0x30, // Dec.00.0
236 0x30, 0x3a, 0x30, 0x30, 0x20, 0x4d, 0x6f, 0x6e, // 0.00.Mon
237 0x2c, 0x20, 0x54, 0x75, 0x65, 0x2c, 0x20, 0x57, // ..Tue..W
238 0x65, 0x64, 0x2c, 0x20, 0x54, 0x68, 0x75, 0x2c, // ed..Thu.
239 0x20, 0x46, 0x72, 0x69, 0x2c, 0x20, 0x53, 0x61, // .Fri..Sa
240 0x74, 0x2c, 0x20, 0x53, 0x75, 0x6e, 0x2c, 0x20, // t..Sun..
241 0x47, 0x4d, 0x54, 0x63, 0x68, 0x75, 0x6e, 0x6b, // GMTchunk
242 0x65, 0x64, 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, // ed.text.
243 0x68, 0x74, 0x6d, 0x6c, 0x2c, 0x69, 0x6d, 0x61, // html.ima
244 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x2c, 0x69, // ge.png.i
245 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x67, // mage.jpg
246 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67, // .image.g
247 0x69, 0x66, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // if.appli
248 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // cation.x
249 0x6d, 0x6c, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // ml.appli
250 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // cation.x
251 0x68, 0x74, 0x6d, 0x6c, 0x2b, 0x78, 0x6d, 0x6c, // html.xml
252 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, // .text.pl
253 0x61, 0x69, 0x6e, 0x2c, 0x74, 0x65, 0x78, 0x74, // ain.text
254 0x2f, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, // .javascr
255 0x69, 0x70, 0x74, 0x2c, 0x70, 0x75, 0x62, 0x6c, // ipt.publ
256 0x69, 0x63, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, // icprivat
257 0x65, 0x6d, 0x61, 0x78, 0x2d, 0x61, 0x67, 0x65, // emax-age
258 0x3d, 0x67, 0x7a, 0x69, 0x70, 0x2c, 0x64, 0x65, // .gzip.de
259 0x66, 0x6c, 0x61, 0x74, 0x65, 0x2c, 0x73, 0x64, // flate.sd
260 0x63, 0x68, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // chcharse
261 0x74, 0x3d, 0x75, 0x74, 0x66, 0x2d, 0x38, 0x63, // t.utf-8c
262 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x3d, 0x69, // harset.i
263 0x73, 0x6f, 0x2d, 0x38, 0x38, 0x35, 0x39, 0x2d, // so-8859-
264 0x31, 0x2c, 0x75, 0x74, 0x66, 0x2d, 0x2c, 0x2a, // 1.utf-..
265 0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e // .enq.0.
267 const int kV3DictionarySize = arraysize(kV3Dictionary);
269 // The HTTP/2 connection header prefix, which must be the first bytes
270 // sent by the client upon starting an HTTP/2 connection, and which
271 // must be followed by a SETTINGS frame.
273 // Equivalent to the string "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
274 // (without the null terminator).
275 const char kHttp2ConnectionHeaderPrefix[] = {
276 0x50, 0x52, 0x49, 0x20, 0x2a, 0x20, 0x48, 0x54, // PRI * HT
277 0x54, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x0d, 0x0a, // TP/2.0..
278 0x0d, 0x0a, 0x53, 0x4d, 0x0d, 0x0a, 0x0d, 0x0a // ..SM....
280 const int kHttp2ConnectionHeaderPrefixSize =
281 arraysize(kHttp2ConnectionHeaderPrefix);
283 const char kHttp2VersionString[] = "HTTP/1.1";
285 // Types of SPDY frames.
286 enum SpdyFrameType {
287 DATA,
288 SYN_STREAM,
289 SYN_REPLY,
290 RST_STREAM,
291 SETTINGS,
292 PING,
293 GOAWAY,
294 HEADERS,
295 WINDOW_UPDATE,
296 CREDENTIAL = 10, // No longer valid. Kept for identifiability.
297 PUSH_PROMISE,
298 CONTINUATION,
299 PRIORITY,
300 // BLOCKED and ALTSVC are recognized extensions.
301 BLOCKED,
302 ALTSVC,
305 // Flags on data packets.
306 enum SpdyDataFlags {
307 DATA_FLAG_NONE = 0x00,
308 DATA_FLAG_FIN = 0x01,
309 DATA_FLAG_END_SEGMENT = 0x02,
310 DATA_FLAG_PADDED = 0x08,
311 DATA_FLAG_COMPRESSED = 0x20,
314 // Flags on control packets
315 enum SpdyControlFlags {
316 CONTROL_FLAG_NONE = 0x00,
317 CONTROL_FLAG_FIN = 0x01,
318 CONTROL_FLAG_UNIDIRECTIONAL = 0x02,
321 enum SpdyPingFlags {
322 PING_FLAG_ACK = 0x01,
325 // Used by HEADERS, PUSH_PROMISE, and CONTINUATION.
326 enum SpdyHeadersFlags {
327 HEADERS_FLAG_END_SEGMENT = 0x02,
328 HEADERS_FLAG_END_HEADERS = 0x04,
329 HEADERS_FLAG_PADDED = 0x08,
330 HEADERS_FLAG_PRIORITY = 0x20,
333 enum SpdyPushPromiseFlags {
334 PUSH_PROMISE_FLAG_END_PUSH_PROMISE = 0x04,
335 PUSH_PROMISE_FLAG_PADDED = 0x08,
338 // Flags on the SETTINGS control frame.
339 enum SpdySettingsControlFlags {
340 SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS = 0x01,
343 enum Http2SettingsControlFlags {
344 SETTINGS_FLAG_ACK = 0x01,
347 // Flags for settings within a SETTINGS frame.
348 enum SpdySettingsFlags {
349 SETTINGS_FLAG_NONE = 0x00,
350 SETTINGS_FLAG_PLEASE_PERSIST = 0x01,
351 SETTINGS_FLAG_PERSISTED = 0x02,
354 // List of known settings. Avoid changing these enum values, as persisted
355 // settings are keyed on them, and they are also exposed in net-internals.
356 enum SpdySettingsIds {
357 SETTINGS_UPLOAD_BANDWIDTH = 0x1,
358 SETTINGS_DOWNLOAD_BANDWIDTH = 0x2,
359 // Network round trip time in milliseconds.
360 SETTINGS_ROUND_TRIP_TIME = 0x3,
361 // The maximum number of simultaneous live streams in each direction.
362 SETTINGS_MAX_CONCURRENT_STREAMS = 0x4,
363 // TCP congestion window in packets.
364 SETTINGS_CURRENT_CWND = 0x5,
365 // Downstream byte retransmission rate in percentage.
366 SETTINGS_DOWNLOAD_RETRANS_RATE = 0x6,
367 // Initial window size in bytes
368 SETTINGS_INITIAL_WINDOW_SIZE = 0x7,
369 // HPACK header table maximum size.
370 SETTINGS_HEADER_TABLE_SIZE = 0x8,
371 // Whether or not server push (PUSH_PROMISE) is enabled.
372 SETTINGS_ENABLE_PUSH = 0x9,
373 // The size of the largest frame payload that a receiver is willing to accept.
374 SETTINGS_MAX_FRAME_SIZE = 0xa,
375 // The maximum size of header list that the sender is prepared to accept.
376 SETTINGS_MAX_HEADER_LIST_SIZE = 0xb,
379 // Status codes for RST_STREAM frames.
380 enum SpdyRstStreamStatus {
381 RST_STREAM_INVALID = 0,
382 RST_STREAM_PROTOCOL_ERROR = 1,
383 RST_STREAM_INVALID_STREAM = 2,
384 RST_STREAM_STREAM_CLOSED = 2, // Equivalent to INVALID_STREAM
385 RST_STREAM_REFUSED_STREAM = 3,
386 RST_STREAM_UNSUPPORTED_VERSION = 4,
387 RST_STREAM_CANCEL = 5,
388 RST_STREAM_INTERNAL_ERROR = 6,
389 RST_STREAM_FLOW_CONTROL_ERROR = 7,
390 RST_STREAM_STREAM_IN_USE = 8,
391 RST_STREAM_STREAM_ALREADY_CLOSED = 9,
392 RST_STREAM_INVALID_CREDENTIALS = 10,
393 // FRAME_TOO_LARGE (defined by SPDY versions 3.1 and below), and
394 // FRAME_SIZE_ERROR (defined by HTTP/2) are mapped to the same internal
395 // reset status.
396 RST_STREAM_FRAME_TOO_LARGE = 11,
397 RST_STREAM_FRAME_SIZE_ERROR = 11,
398 RST_STREAM_SETTINGS_TIMEOUT = 12,
399 RST_STREAM_CONNECT_ERROR = 13,
400 RST_STREAM_ENHANCE_YOUR_CALM = 14,
401 RST_STREAM_INADEQUATE_SECURITY = 15,
402 RST_STREAM_HTTP_1_1_REQUIRED = 16,
403 RST_STREAM_NUM_STATUS_CODES = 17
406 // Status codes for GOAWAY frames.
407 enum SpdyGoAwayStatus {
408 GOAWAY_OK = 0,
409 GOAWAY_NO_ERROR = GOAWAY_OK,
410 GOAWAY_PROTOCOL_ERROR = 1,
411 GOAWAY_INTERNAL_ERROR = 2,
412 GOAWAY_FLOW_CONTROL_ERROR = 3,
413 GOAWAY_SETTINGS_TIMEOUT = 4,
414 GOAWAY_STREAM_CLOSED = 5,
415 GOAWAY_FRAME_SIZE_ERROR = 6,
416 GOAWAY_REFUSED_STREAM = 7,
417 GOAWAY_CANCEL = 8,
418 GOAWAY_COMPRESSION_ERROR = 9,
419 GOAWAY_CONNECT_ERROR = 10,
420 GOAWAY_ENHANCE_YOUR_CALM = 11,
421 GOAWAY_INADEQUATE_SECURITY = 12,
422 GOAWAY_HTTP_1_1_REQUIRED = 13
425 // A SPDY priority is a number between 0 and 7 (inclusive).
426 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a
427 // number between 0 and 3.
428 typedef uint8 SpdyPriority;
430 typedef std::map<std::string, std::string> SpdyNameValueBlock;
432 typedef uint64 SpdyPingId;
434 typedef std::string SpdyProtocolId;
436 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any,
437 // but is good to do anyway.
438 class NET_EXPORT_PRIVATE SpdyConstants {
439 public:
440 // Returns true if a given on-the-wire enumeration of a frame type is valid
441 // for a given protocol version, false otherwise.
442 static bool IsValidFrameType(SpdyMajorVersion version, int frame_type_field);
444 // Parses a frame type from an on-the-wire enumeration of a given protocol
445 // version.
446 // Behavior is undefined for invalid frame type fields; consumers should first
447 // use IsValidFrameType() to verify validity of frame type fields.
448 static SpdyFrameType ParseFrameType(SpdyMajorVersion version,
449 int frame_type_field);
451 // Serializes a given frame type to the on-the-wire enumeration value for the
452 // given protocol version.
453 // Returns -1 on failure (I.E. Invalid frame type for the given version).
454 static int SerializeFrameType(SpdyMajorVersion version,
455 SpdyFrameType frame_type);
457 // Returns the frame type for non-control (i.e. data) frames
458 // in the given SPDY version.
459 static int DataFrameType(SpdyMajorVersion version);
461 // Returns true if a given on-the-wire enumeration of a setting id is valid
462 // for a given protocol version, false otherwise.
463 static bool IsValidSettingId(SpdyMajorVersion version, int setting_id_field);
465 // Parses a setting id from an on-the-wire enumeration of a given protocol
466 // version.
467 // Behavior is undefined for invalid setting id fields; consumers should first
468 // use IsValidSettingId() to verify validity of setting id fields.
469 static SpdySettingsIds ParseSettingId(SpdyMajorVersion version,
470 int setting_id_field);
472 // Serializes a given setting id to the on-the-wire enumeration value for the
473 // given protocol version.
474 // Returns -1 on failure (I.E. Invalid setting id for the given version).
475 static int SerializeSettingId(SpdyMajorVersion version, SpdySettingsIds id);
477 // Returns true if a given on-the-wire enumeration of a RST_STREAM status code
478 // is valid for a given protocol version, false otherwise.
479 static bool IsValidRstStreamStatus(SpdyMajorVersion version,
480 int rst_stream_status_field);
482 // Parses a RST_STREAM status code from an on-the-wire enumeration of a given
483 // protocol version.
484 // Behavior is undefined for invalid RST_STREAM status code fields; consumers
485 // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM
486 // status code fields..
487 static SpdyRstStreamStatus ParseRstStreamStatus(SpdyMajorVersion version,
488 int rst_stream_status_field);
490 // Serializes a given RST_STREAM status code to the on-the-wire enumeration
491 // value for the given protocol version.
492 // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given
493 // version).
494 static int SerializeRstStreamStatus(SpdyMajorVersion version,
495 SpdyRstStreamStatus rst_stream_status);
497 // Returns true if a given on-the-wire enumeration of a GOAWAY status code is
498 // valid for the given protocol version, false otherwise.
499 static bool IsValidGoAwayStatus(SpdyMajorVersion version,
500 int goaway_status_field);
502 // Parses a GOAWAY status from an on-the-wire enumeration of a given protocol
503 // version.
504 // Behavior is undefined for invalid GOAWAY status fields; consumers should
505 // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields.
506 static SpdyGoAwayStatus ParseGoAwayStatus(SpdyMajorVersion version,
507 int goaway_status_field);
509 // Serializes a given GOAWAY status to the on-the-wire enumeration value for
510 // the given protocol version.
511 // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version).
512 static int SerializeGoAwayStatus(SpdyMajorVersion version,
513 SpdyGoAwayStatus status);
515 // Size, in bytes, of the data frame header. Future versions of SPDY
516 // will likely vary this, so we allow for the flexibility of a function call
517 // for this value as opposed to a constant.
518 static size_t GetDataFrameMinimumSize(SpdyMajorVersion version);
520 // Size, in bytes, of the control frame header.
521 static size_t GetControlFrameHeaderSize(SpdyMajorVersion version);
523 static size_t GetPrefixLength(SpdyFrameType type, SpdyMajorVersion version);
525 static size_t GetFrameMaximumSize(SpdyMajorVersion version);
527 // Returns the size of a header block size field. Valid only for SPDY
528 // versions <= 3.
529 static size_t GetSizeOfSizeField(SpdyMajorVersion version);
531 // Returns the size (in bytes) of a wire setting ID and value.
532 static size_t GetSettingSize(SpdyMajorVersion version);
534 static SpdyMajorVersion ParseMajorVersion(int version_number);
536 static int SerializeMajorVersion(SpdyMajorVersion version);
538 static std::string GetVersionString(SpdyMajorVersion version);
541 class SpdyFrame;
542 typedef SpdyFrame SpdySerializedFrame;
544 class SpdyFrameVisitor;
546 // Intermediate representation for SPDY frames.
547 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is
548 // gone.
549 class NET_EXPORT_PRIVATE SpdyFrameIR {
550 public:
551 virtual ~SpdyFrameIR() {}
553 virtual void Visit(SpdyFrameVisitor* visitor) const = 0;
555 protected:
556 SpdyFrameIR() {}
558 private:
559 DISALLOW_COPY_AND_ASSIGN(SpdyFrameIR);
562 // Abstract class intended to be inherited by IRs that have a stream associated
563 // to them.
564 class NET_EXPORT_PRIVATE SpdyFrameWithStreamIdIR : public SpdyFrameIR {
565 public:
566 ~SpdyFrameWithStreamIdIR() override {}
567 SpdyStreamId stream_id() const { return stream_id_; }
568 void set_stream_id(SpdyStreamId stream_id) {
569 DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
570 stream_id_ = stream_id;
573 protected:
574 explicit SpdyFrameWithStreamIdIR(SpdyStreamId stream_id) {
575 set_stream_id(stream_id);
578 private:
579 SpdyStreamId stream_id_;
581 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithStreamIdIR);
584 // Abstract class intended to be inherited by IRs that have the option of a FIN
585 // flag. Implies SpdyFrameWithStreamIdIR.
586 class NET_EXPORT_PRIVATE SpdyFrameWithFinIR : public SpdyFrameWithStreamIdIR {
587 public:
588 ~SpdyFrameWithFinIR() override {}
589 bool fin() const { return fin_; }
590 void set_fin(bool fin) { fin_ = fin; }
592 protected:
593 explicit SpdyFrameWithFinIR(SpdyStreamId stream_id)
594 : SpdyFrameWithStreamIdIR(stream_id),
595 fin_(false) {}
597 private:
598 bool fin_;
600 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithFinIR);
603 // Abstract class intended to be inherited by IRs that contain a name-value
604 // block. Implies SpdyFrameWithFinIR.
605 class NET_EXPORT_PRIVATE SpdyFrameWithNameValueBlockIR
606 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) {
607 public:
608 const SpdyNameValueBlock& name_value_block() const {
609 return name_value_block_;
611 void set_name_value_block(const SpdyNameValueBlock& name_value_block) {
612 // Deep copy.
613 name_value_block_ = name_value_block;
615 void SetHeader(const base::StringPiece& name,
616 const base::StringPiece& value) {
617 name_value_block_[name.as_string()] = value.as_string();
619 SpdyNameValueBlock* mutable_name_value_block() {
620 return &name_value_block_;
623 protected:
624 explicit SpdyFrameWithNameValueBlockIR(SpdyStreamId stream_id);
625 ~SpdyFrameWithNameValueBlockIR() override;
627 private:
628 SpdyNameValueBlock name_value_block_;
630 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithNameValueBlockIR);
633 class NET_EXPORT_PRIVATE SpdyDataIR
634 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) {
635 public:
636 // Performs deep copy on data.
637 SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data);
639 // Use in conjunction with SetDataShallow() for shallow-copy on data.
640 explicit SpdyDataIR(SpdyStreamId stream_id);
642 ~SpdyDataIR() override;
644 base::StringPiece data() const { return data_; }
646 bool padded() const { return padded_; }
648 int padding_payload_len() const { return padding_payload_len_; }
650 void set_padding_len(int padding_len) {
651 DCHECK_GT(padding_len, 0);
652 DCHECK_LE(padding_len, kPaddingSizePerFrame);
653 padded_ = true;
654 // The pad field takes one octet on the wire.
655 padding_payload_len_ = padding_len - 1;
658 // Deep-copy of data (keep private copy).
659 void SetDataDeep(const base::StringPiece& data) {
660 data_store_.reset(new std::string(data.data(), data.length()));
661 data_ = *(data_store_.get());
664 // Shallow-copy of data (do not keep private copy).
665 void SetDataShallow(const base::StringPiece& data) {
666 data_store_.reset();
667 data_ = data;
670 void Visit(SpdyFrameVisitor* visitor) const override;
672 private:
673 // Used to store data that this SpdyDataIR should own.
674 scoped_ptr<std::string> data_store_;
675 base::StringPiece data_;
677 bool padded_;
678 // padding_payload_len_ = desired padding length - len(padding length field).
679 int padding_payload_len_;
681 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR);
684 class NET_EXPORT_PRIVATE SpdySynStreamIR
685 : public SpdyFrameWithNameValueBlockIR {
686 public:
687 explicit SpdySynStreamIR(SpdyStreamId stream_id)
688 : SpdyFrameWithNameValueBlockIR(stream_id),
689 associated_to_stream_id_(0),
690 priority_(0),
691 unidirectional_(false) {}
692 SpdyStreamId associated_to_stream_id() const {
693 return associated_to_stream_id_;
695 void set_associated_to_stream_id(SpdyStreamId stream_id) {
696 associated_to_stream_id_ = stream_id;
698 SpdyPriority priority() const { return priority_; }
699 void set_priority(SpdyPriority priority) { priority_ = priority; }
700 bool unidirectional() const { return unidirectional_; }
701 void set_unidirectional(bool unidirectional) {
702 unidirectional_ = unidirectional;
705 void Visit(SpdyFrameVisitor* visitor) const override;
707 private:
708 SpdyStreamId associated_to_stream_id_;
709 SpdyPriority priority_;
710 bool unidirectional_;
712 DISALLOW_COPY_AND_ASSIGN(SpdySynStreamIR);
715 class NET_EXPORT_PRIVATE SpdySynReplyIR : public SpdyFrameWithNameValueBlockIR {
716 public:
717 explicit SpdySynReplyIR(SpdyStreamId stream_id)
718 : SpdyFrameWithNameValueBlockIR(stream_id) {}
720 void Visit(SpdyFrameVisitor* visitor) const override;
722 private:
723 DISALLOW_COPY_AND_ASSIGN(SpdySynReplyIR);
726 class NET_EXPORT_PRIVATE SpdyRstStreamIR : public SpdyFrameWithStreamIdIR {
727 public:
728 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyRstStreamStatus status,
729 base::StringPiece description);
731 ~SpdyRstStreamIR() override;
733 SpdyRstStreamStatus status() const {
734 return status_;
736 void set_status(SpdyRstStreamStatus status) {
737 status_ = status;
740 base::StringPiece description() const { return description_; }
742 void set_description(base::StringPiece description) {
743 description_ = description;
746 void Visit(SpdyFrameVisitor* visitor) const override;
748 private:
749 SpdyRstStreamStatus status_;
750 base::StringPiece description_;
752 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR);
755 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR {
756 public:
757 // Associates flags with a value.
758 struct Value {
759 Value() : persist_value(false),
760 persisted(false),
761 value(0) {}
762 bool persist_value;
763 bool persisted;
764 int32 value;
766 typedef std::map<SpdySettingsIds, Value> ValueMap;
768 SpdySettingsIR();
770 ~SpdySettingsIR() override;
772 // Overwrites as appropriate.
773 const ValueMap& values() const { return values_; }
774 void AddSetting(SpdySettingsIds id,
775 bool persist_value,
776 bool persisted,
777 int32 value) {
778 values_[id].persist_value = persist_value;
779 values_[id].persisted = persisted;
780 values_[id].value = value;
783 bool clear_settings() const { return clear_settings_; }
784 void set_clear_settings(bool clear_settings) {
785 clear_settings_ = clear_settings;
787 bool is_ack() const { return is_ack_; }
788 void set_is_ack(bool is_ack) {
789 is_ack_ = is_ack;
792 void Visit(SpdyFrameVisitor* visitor) const override;
794 private:
795 ValueMap values_;
796 bool clear_settings_;
797 bool is_ack_;
799 DISALLOW_COPY_AND_ASSIGN(SpdySettingsIR);
802 class NET_EXPORT_PRIVATE SpdyPingIR : public SpdyFrameIR {
803 public:
804 explicit SpdyPingIR(SpdyPingId id) : id_(id), is_ack_(false) {}
805 SpdyPingId id() const { return id_; }
807 // ACK logic is valid only for SPDY versions 4 and above.
808 bool is_ack() const { return is_ack_; }
809 void set_is_ack(bool is_ack) { is_ack_ = is_ack; }
811 void Visit(SpdyFrameVisitor* visitor) const override;
813 private:
814 SpdyPingId id_;
815 bool is_ack_;
817 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR);
820 class NET_EXPORT_PRIVATE SpdyGoAwayIR : public SpdyFrameIR {
821 public:
822 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, SpdyGoAwayStatus status,
823 const base::StringPiece& description);
824 ~SpdyGoAwayIR() override;
825 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; }
826 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) {
827 DCHECK_LE(0u, last_good_stream_id);
828 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask);
829 last_good_stream_id_ = last_good_stream_id;
831 SpdyGoAwayStatus status() const { return status_; }
832 void set_status(SpdyGoAwayStatus status) {
833 // TODO(hkhalil): Check valid ranges of status?
834 status_ = status;
837 const base::StringPiece& description() const;
839 void Visit(SpdyFrameVisitor* visitor) const override;
841 private:
842 SpdyStreamId last_good_stream_id_;
843 SpdyGoAwayStatus status_;
844 const base::StringPiece description_;
846 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR);
849 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithNameValueBlockIR {
850 public:
851 explicit SpdyHeadersIR(SpdyStreamId stream_id)
852 : SpdyFrameWithNameValueBlockIR(stream_id),
853 has_priority_(false),
854 priority_(0),
855 padded_(false),
856 padding_payload_len_(0) {}
858 void Visit(SpdyFrameVisitor* visitor) const override;
860 bool has_priority() const { return has_priority_; }
861 void set_has_priority(bool has_priority) { has_priority_ = has_priority; }
862 uint32 priority() const { return priority_; }
863 void set_priority(SpdyPriority priority) { priority_ = priority; }
865 bool padded() const { return padded_; }
866 int padding_payload_len() const { return padding_payload_len_; }
867 void set_padding_len(int padding_len) {
868 DCHECK_GT(padding_len, 0);
869 DCHECK_LE(padding_len, kPaddingSizePerFrame);
870 padded_ = true;
871 // The pad field takes one octet on the wire.
872 padding_payload_len_ = padding_len - 1;
875 private:
876 bool has_priority_;
877 // 31-bit priority.
878 uint32 priority_;
880 bool padded_;
881 int padding_payload_len_;
883 DISALLOW_COPY_AND_ASSIGN(SpdyHeadersIR);
886 class NET_EXPORT_PRIVATE SpdyWindowUpdateIR : public SpdyFrameWithStreamIdIR {
887 public:
888 SpdyWindowUpdateIR(SpdyStreamId stream_id, int32 delta)
889 : SpdyFrameWithStreamIdIR(stream_id) {
890 set_delta(delta);
892 int32 delta() const { return delta_; }
893 void set_delta(int32 delta) {
894 DCHECK_LT(0, delta);
895 DCHECK_LE(delta, kSpdyMaximumWindowSize);
896 delta_ = delta;
899 void Visit(SpdyFrameVisitor* visitor) const override;
901 private:
902 int32 delta_;
904 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateIR);
907 class NET_EXPORT_PRIVATE SpdyBlockedIR
908 : public NON_EXPORTED_BASE(SpdyFrameWithStreamIdIR) {
909 public:
910 explicit SpdyBlockedIR(SpdyStreamId stream_id)
911 : SpdyFrameWithStreamIdIR(stream_id) {}
913 void Visit(SpdyFrameVisitor* visitor) const override;
915 private:
916 DISALLOW_COPY_AND_ASSIGN(SpdyBlockedIR);
919 class NET_EXPORT_PRIVATE SpdyPushPromiseIR
920 : public SpdyFrameWithNameValueBlockIR {
921 public:
922 SpdyPushPromiseIR(SpdyStreamId stream_id, SpdyStreamId promised_stream_id)
923 : SpdyFrameWithNameValueBlockIR(stream_id),
924 promised_stream_id_(promised_stream_id),
925 padded_(false),
926 padding_payload_len_(0) {}
927 SpdyStreamId promised_stream_id() const { return promised_stream_id_; }
928 void set_promised_stream_id(SpdyStreamId id) { promised_stream_id_ = id; }
930 void Visit(SpdyFrameVisitor* visitor) const override;
932 bool padded() const { return padded_; }
933 int padding_payload_len() const { return padding_payload_len_; }
934 void set_padding_len(int padding_len) {
935 DCHECK_GT(padding_len, 0);
936 DCHECK_LE(padding_len, kPaddingSizePerFrame);
937 padded_ = true;
938 // The pad field takes one octet on the wire.
939 padding_payload_len_ = padding_len - 1;
942 private:
943 SpdyStreamId promised_stream_id_;
945 bool padded_;
946 int padding_payload_len_;
948 DISALLOW_COPY_AND_ASSIGN(SpdyPushPromiseIR);
951 // TODO(jgraettinger): This representation needs review. SpdyContinuationIR
952 // needs to frame a portion of a single, arbitrarily-broken encoded buffer.
953 class NET_EXPORT_PRIVATE SpdyContinuationIR
954 : public SpdyFrameWithNameValueBlockIR {
955 public:
956 explicit SpdyContinuationIR(SpdyStreamId stream_id)
957 : SpdyFrameWithNameValueBlockIR(stream_id),
958 end_headers_(false) {}
960 void Visit(SpdyFrameVisitor* visitor) const override;
962 bool end_headers() const { return end_headers_; }
963 void set_end_headers(bool end_headers) {end_headers_ = end_headers;}
965 private:
966 bool end_headers_;
967 DISALLOW_COPY_AND_ASSIGN(SpdyContinuationIR);
970 class NET_EXPORT_PRIVATE SpdyAltSvcIR : public SpdyFrameWithStreamIdIR {
971 public:
972 explicit SpdyAltSvcIR(SpdyStreamId stream_id);
974 uint32 max_age() const { return max_age_; }
975 uint16 port() const { return port_; }
976 SpdyProtocolId protocol_id() const {
977 return protocol_id_;
979 std::string host() const { return host_; }
980 std::string origin() const { return origin_; }
982 void set_max_age(uint32 max_age) { max_age_ = max_age; }
983 void set_port(uint16 port) { port_ = port; }
984 void set_protocol_id(SpdyProtocolId protocol_id) {
985 protocol_id_ = protocol_id;
987 void set_host(std::string host) { host_ = host; }
988 void set_origin(std::string origin) { origin_ = origin; }
990 void Visit(SpdyFrameVisitor* visitor) const override;
992 private:
993 uint32 max_age_;
994 uint16 port_;
995 SpdyProtocolId protocol_id_;
996 std::string host_;
997 std::string origin_;
998 DISALLOW_COPY_AND_ASSIGN(SpdyAltSvcIR);
1001 class NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR {
1002 public:
1003 explicit SpdyPriorityIR(SpdyStreamId stream_id);
1004 explicit SpdyPriorityIR(SpdyStreamId stream_id,
1005 SpdyStreamId parent_stream_id,
1006 uint8 weight,
1007 bool exclusive);
1008 SpdyStreamId parent_stream_id() const { return parent_stream_id_; }
1009 void set_parent_stream_id(SpdyStreamId id) { parent_stream_id_ = id; }
1010 uint8 weight() const { return weight_; }
1011 void set_weight(uint8 weight) { weight_ = weight; }
1012 bool exclusive() const { return exclusive_; }
1013 void set_exclusive(bool exclusive) { exclusive_ = exclusive; }
1015 void Visit(SpdyFrameVisitor* visitor) const override;
1017 private:
1018 SpdyStreamId parent_stream_id_;
1019 uint8 weight_;
1020 bool exclusive_;
1021 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR);
1024 // -------------------------------------------------------------------------
1025 // Wrapper classes for various SPDY frames.
1027 // All Spdy Frame types derive from this SpdyFrame class.
1028 class SpdyFrame {
1029 public:
1030 // Create a SpdyFrame using a pre-created buffer.
1031 // If |owns_buffer| is true, this class takes ownership of the buffer
1032 // and will delete it on cleanup. The buffer must have been created using
1033 // new char[].
1034 // If |owns_buffer| is false, the caller retains ownership of the buffer and
1035 // is responsible for making sure the buffer outlives this frame. In other
1036 // words, this class does NOT create a copy of the buffer.
1037 SpdyFrame(char* data, size_t size, bool owns_buffer)
1038 : frame_(data),
1039 size_(size),
1040 owns_buffer_(owns_buffer) {
1041 DCHECK(frame_);
1044 ~SpdyFrame() {
1045 if (owns_buffer_) {
1046 delete [] frame_;
1048 frame_ = NULL;
1051 // Provides access to the frame bytes, which is a buffer containing
1052 // the frame packed as expected for sending over the wire.
1053 char* data() const { return frame_; }
1055 // Returns the actual size of the underlying buffer.
1056 size_t size() const { return size_; }
1058 protected:
1059 char* frame_;
1061 private:
1062 size_t size_;
1063 bool owns_buffer_;
1064 DISALLOW_COPY_AND_ASSIGN(SpdyFrame);
1067 // This interface is for classes that want to process SpdyFrameIRs without
1068 // having to know what type they are. An instance of this interface can be
1069 // passed to a SpdyFrameIR's Visit method, and the appropriate type-specific
1070 // method of this class will be called.
1071 class SpdyFrameVisitor {
1072 public:
1073 virtual void VisitSynStream(const SpdySynStreamIR& syn_stream) = 0;
1074 virtual void VisitSynReply(const SpdySynReplyIR& syn_reply) = 0;
1075 virtual void VisitRstStream(const SpdyRstStreamIR& rst_stream) = 0;
1076 virtual void VisitSettings(const SpdySettingsIR& settings) = 0;
1077 virtual void VisitPing(const SpdyPingIR& ping) = 0;
1078 virtual void VisitGoAway(const SpdyGoAwayIR& goaway) = 0;
1079 virtual void VisitHeaders(const SpdyHeadersIR& headers) = 0;
1080 virtual void VisitWindowUpdate(const SpdyWindowUpdateIR& window_update) = 0;
1081 virtual void VisitBlocked(const SpdyBlockedIR& blocked) = 0;
1082 virtual void VisitPushPromise(const SpdyPushPromiseIR& push_promise) = 0;
1083 virtual void VisitContinuation(const SpdyContinuationIR& continuation) = 0;
1084 virtual void VisitAltSvc(const SpdyAltSvcIR& altsvc) = 0;
1085 virtual void VisitPriority(const SpdyPriorityIR& priority) = 0;
1086 virtual void VisitData(const SpdyDataIR& data) = 0;
1088 protected:
1089 SpdyFrameVisitor() {}
1090 virtual ~SpdyFrameVisitor() {}
1092 private:
1093 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor);
1096 } // namespace net
1098 #endif // NET_SPDY_SPDY_PROTOCOL_H_