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_
18 #include "base/basictypes.h"
19 #include "base/compiler_specific.h"
20 #include "base/logging.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "base/strings/string_piece.h"
23 #include "base/sys_byteorder.h"
24 #include "net/base/net_export.h"
25 #include "net/spdy/spdy_alt_svc_wire_format.h"
26 #include "net/spdy/spdy_bitmasks.h"
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
{
36 SPDY_MIN_VERSION
= SPDY2
,
39 SPDY_MAX_VERSION
= HTTP2
42 // A SPDY stream id is a 31 bit entity.
43 typedef uint32 SpdyStreamId
;
45 // Specifies the stream ID used to denote the current session (for
47 const SpdyStreamId kSessionFlowControlStreamId
= 0;
49 // The maxmium possible control frame size allowed by the spec.
50 const int32 kSpdyMaxControlFrameSize
= (1 << 24) - 1;
52 // The maximum control frame size we accept.
53 const int32 kControlFrameSizeLimit
= 1 << 14;
55 // Maximum window size for a Spdy stream or session.
56 const int32 kSpdyMaximumWindowSize
= 0x7FFFFFFF; // Max signed 32bit int
58 // Maximum padding size in octets for one DATA or HEADERS or PUSH_PROMISE frame.
59 const int32 kPaddingSizePerFrame
= 256;
62 // This is just a hacked dictionary to use for shrinking HTTP-like headers.
63 const char kV2Dictionary
[] =
64 "optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-"
65 "languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi"
66 "f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser"
67 "-agent10010120020120220320420520630030130230330430530630740040140240340440"
68 "5406407408409410411412413414415416417500501502503504505accept-rangesageeta"
69 "glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic"
70 "ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran"
71 "sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati"
72 "oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo"
73 "ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe"
74 "pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic"
75 "ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1"
77 const int kV2DictionarySize
= arraysize(kV2Dictionary
);
80 const char kV3Dictionary
[] = {
81 0x00, 0x00, 0x00, 0x07, 0x6f, 0x70, 0x74, 0x69, // ....opti
82 0x6f, 0x6e, 0x73, 0x00, 0x00, 0x00, 0x04, 0x68, // ons....h
83 0x65, 0x61, 0x64, 0x00, 0x00, 0x00, 0x04, 0x70, // ead....p
84 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x03, 0x70, // ost....p
85 0x75, 0x74, 0x00, 0x00, 0x00, 0x06, 0x64, 0x65, // ut....de
86 0x6c, 0x65, 0x74, 0x65, 0x00, 0x00, 0x00, 0x05, // lete....
87 0x74, 0x72, 0x61, 0x63, 0x65, 0x00, 0x00, 0x00, // trace...
88 0x06, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x00, // .accept.
89 0x00, 0x00, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70, // ...accep
90 0x74, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // t-charse
91 0x74, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x63, 0x63, // t....acc
92 0x65, 0x70, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // ept-enco
93 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x0f, // ding....
94 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x6c, // accept-l
95 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x00, // anguage.
96 0x00, 0x00, 0x0d, 0x61, 0x63, 0x63, 0x65, 0x70, // ...accep
97 0x74, 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x73, // t-ranges
98 0x00, 0x00, 0x00, 0x03, 0x61, 0x67, 0x65, 0x00, // ....age.
99 0x00, 0x00, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, // ...allow
100 0x00, 0x00, 0x00, 0x0d, 0x61, 0x75, 0x74, 0x68, // ....auth
101 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, // orizatio
102 0x6e, 0x00, 0x00, 0x00, 0x0d, 0x63, 0x61, 0x63, // n....cac
103 0x68, 0x65, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, // he-contr
104 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, // ol....co
105 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, // nnection
106 0x00, 0x00, 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, // ....cont
107 0x65, 0x6e, 0x74, 0x2d, 0x62, 0x61, 0x73, 0x65, // ent-base
108 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, 0x6e, 0x74, // ....cont
109 0x65, 0x6e, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // ent-enco
110 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, // ding....
111 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, // content-
112 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, // language
113 0x00, 0x00, 0x00, 0x0e, 0x63, 0x6f, 0x6e, 0x74, // ....cont
114 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x65, 0x6e, 0x67, // ent-leng
115 0x74, 0x68, 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, // th....co
116 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x6f, // ntent-lo
117 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, // cation..
118 0x00, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // ..conten
119 0x74, 0x2d, 0x6d, 0x64, 0x35, 0x00, 0x00, 0x00, // t-md5...
120 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, // .content
121 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, // -range..
122 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // ..conten
123 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00, // t-type..
124 0x00, 0x04, 0x64, 0x61, 0x74, 0x65, 0x00, 0x00, // ..date..
125 0x00, 0x04, 0x65, 0x74, 0x61, 0x67, 0x00, 0x00, // ..etag..
126 0x00, 0x06, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, // ..expect
127 0x00, 0x00, 0x00, 0x07, 0x65, 0x78, 0x70, 0x69, // ....expi
128 0x72, 0x65, 0x73, 0x00, 0x00, 0x00, 0x04, 0x66, // res....f
129 0x72, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x04, 0x68, // rom....h
130 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x08, 0x69, // ost....i
131 0x66, 0x2d, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, // f-match.
132 0x00, 0x00, 0x11, 0x69, 0x66, 0x2d, 0x6d, 0x6f, // ...if-mo
133 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x2d, 0x73, // dified-s
134 0x69, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x0d, // ince....
135 0x69, 0x66, 0x2d, 0x6e, 0x6f, 0x6e, 0x65, 0x2d, // if-none-
136 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, 0x00, 0x00, // match...
137 0x08, 0x69, 0x66, 0x2d, 0x72, 0x61, 0x6e, 0x67, // .if-rang
138 0x65, 0x00, 0x00, 0x00, 0x13, 0x69, 0x66, 0x2d, // e....if-
139 0x75, 0x6e, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, // unmodifi
140 0x65, 0x64, 0x2d, 0x73, 0x69, 0x6e, 0x63, 0x65, // ed-since
141 0x00, 0x00, 0x00, 0x0d, 0x6c, 0x61, 0x73, 0x74, // ....last
142 0x2d, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, // -modifie
143 0x64, 0x00, 0x00, 0x00, 0x08, 0x6c, 0x6f, 0x63, // d....loc
144 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, // ation...
145 0x0c, 0x6d, 0x61, 0x78, 0x2d, 0x66, 0x6f, 0x72, // .max-for
146 0x77, 0x61, 0x72, 0x64, 0x73, 0x00, 0x00, 0x00, // wards...
147 0x06, 0x70, 0x72, 0x61, 0x67, 0x6d, 0x61, 0x00, // .pragma.
148 0x00, 0x00, 0x12, 0x70, 0x72, 0x6f, 0x78, 0x79, // ...proxy
149 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, // -authent
150 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, // icate...
151 0x13, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2d, 0x61, // .proxy-a
152 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, // uthoriza
153 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, // tion....
154 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, 0x00, // range...
155 0x07, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, // .referer
156 0x00, 0x00, 0x00, 0x0b, 0x72, 0x65, 0x74, 0x72, // ....retr
157 0x79, 0x2d, 0x61, 0x66, 0x74, 0x65, 0x72, 0x00, // y-after.
158 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, // ...serve
159 0x72, 0x00, 0x00, 0x00, 0x02, 0x74, 0x65, 0x00, // r....te.
160 0x00, 0x00, 0x07, 0x74, 0x72, 0x61, 0x69, 0x6c, // ...trail
161 0x65, 0x72, 0x00, 0x00, 0x00, 0x11, 0x74, 0x72, // er....tr
162 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x2d, 0x65, // ansfer-e
163 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x00, // ncoding.
164 0x00, 0x00, 0x07, 0x75, 0x70, 0x67, 0x72, 0x61, // ...upgra
165 0x64, 0x65, 0x00, 0x00, 0x00, 0x0a, 0x75, 0x73, // de....us
166 0x65, 0x72, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74, // er-agent
167 0x00, 0x00, 0x00, 0x04, 0x76, 0x61, 0x72, 0x79, // ....vary
168 0x00, 0x00, 0x00, 0x03, 0x76, 0x69, 0x61, 0x00, // ....via.
169 0x00, 0x00, 0x07, 0x77, 0x61, 0x72, 0x6e, 0x69, // ...warni
170 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, 0x77, 0x77, // ng....ww
171 0x77, 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, // w-authen
172 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, // ticate..
173 0x00, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, // ..method
174 0x00, 0x00, 0x00, 0x03, 0x67, 0x65, 0x74, 0x00, // ....get.
175 0x00, 0x00, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, // ...statu
176 0x73, 0x00, 0x00, 0x00, 0x06, 0x32, 0x30, 0x30, // s....200
177 0x20, 0x4f, 0x4b, 0x00, 0x00, 0x00, 0x07, 0x76, // .OK....v
178 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, 0x00, // ersion..
179 0x00, 0x08, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, // ..HTTP.1
180 0x2e, 0x31, 0x00, 0x00, 0x00, 0x03, 0x75, 0x72, // .1....ur
181 0x6c, 0x00, 0x00, 0x00, 0x06, 0x70, 0x75, 0x62, // l....pub
182 0x6c, 0x69, 0x63, 0x00, 0x00, 0x00, 0x0a, 0x73, // lic....s
183 0x65, 0x74, 0x2d, 0x63, 0x6f, 0x6f, 0x6b, 0x69, // et-cooki
184 0x65, 0x00, 0x00, 0x00, 0x0a, 0x6b, 0x65, 0x65, // e....kee
185 0x70, 0x2d, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x00, // p-alive.
186 0x00, 0x00, 0x06, 0x6f, 0x72, 0x69, 0x67, 0x69, // ...origi
187 0x6e, 0x31, 0x30, 0x30, 0x31, 0x30, 0x31, 0x32, // n1001012
188 0x30, 0x31, 0x32, 0x30, 0x32, 0x32, 0x30, 0x35, // 01202205
189 0x32, 0x30, 0x36, 0x33, 0x30, 0x30, 0x33, 0x30, // 20630030
190 0x32, 0x33, 0x30, 0x33, 0x33, 0x30, 0x34, 0x33, // 23033043
191 0x30, 0x35, 0x33, 0x30, 0x36, 0x33, 0x30, 0x37, // 05306307
192 0x34, 0x30, 0x32, 0x34, 0x30, 0x35, 0x34, 0x30, // 40240540
193 0x36, 0x34, 0x30, 0x37, 0x34, 0x30, 0x38, 0x34, // 64074084
194 0x30, 0x39, 0x34, 0x31, 0x30, 0x34, 0x31, 0x31, // 09410411
195 0x34, 0x31, 0x32, 0x34, 0x31, 0x33, 0x34, 0x31, // 41241341
196 0x34, 0x34, 0x31, 0x35, 0x34, 0x31, 0x36, 0x34, // 44154164
197 0x31, 0x37, 0x35, 0x30, 0x32, 0x35, 0x30, 0x34, // 17502504
198 0x35, 0x30, 0x35, 0x32, 0x30, 0x33, 0x20, 0x4e, // 505203.N
199 0x6f, 0x6e, 0x2d, 0x41, 0x75, 0x74, 0x68, 0x6f, // on-Autho
200 0x72, 0x69, 0x74, 0x61, 0x74, 0x69, 0x76, 0x65, // ritative
201 0x20, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, // .Informa
202 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x30, 0x34, 0x20, // tion204.
203 0x4e, 0x6f, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x65, // No.Conte
204 0x6e, 0x74, 0x33, 0x30, 0x31, 0x20, 0x4d, 0x6f, // nt301.Mo
205 0x76, 0x65, 0x64, 0x20, 0x50, 0x65, 0x72, 0x6d, // ved.Perm
206 0x61, 0x6e, 0x65, 0x6e, 0x74, 0x6c, 0x79, 0x34, // anently4
207 0x30, 0x30, 0x20, 0x42, 0x61, 0x64, 0x20, 0x52, // 00.Bad.R
208 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x34, 0x30, // equest40
209 0x31, 0x20, 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68, // 1.Unauth
210 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64, 0x34, 0x30, // orized40
211 0x33, 0x20, 0x46, 0x6f, 0x72, 0x62, 0x69, 0x64, // 3.Forbid
212 0x64, 0x65, 0x6e, 0x34, 0x30, 0x34, 0x20, 0x4e, // den404.N
213 0x6f, 0x74, 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, // ot.Found
214 0x35, 0x30, 0x30, 0x20, 0x49, 0x6e, 0x74, 0x65, // 500.Inte
215 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x53, 0x65, 0x72, // rnal.Ser
216 0x76, 0x65, 0x72, 0x20, 0x45, 0x72, 0x72, 0x6f, // ver.Erro
217 0x72, 0x35, 0x30, 0x31, 0x20, 0x4e, 0x6f, 0x74, // r501.Not
218 0x20, 0x49, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, // .Impleme
219 0x6e, 0x74, 0x65, 0x64, 0x35, 0x30, 0x33, 0x20, // nted503.
220 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, // Service.
221 0x55, 0x6e, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, // Unavaila
222 0x62, 0x6c, 0x65, 0x4a, 0x61, 0x6e, 0x20, 0x46, // bleJan.F
223 0x65, 0x62, 0x20, 0x4d, 0x61, 0x72, 0x20, 0x41, // eb.Mar.A
224 0x70, 0x72, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x4a, // pr.May.J
225 0x75, 0x6e, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x41, // un.Jul.A
226 0x75, 0x67, 0x20, 0x53, 0x65, 0x70, 0x74, 0x20, // ug.Sept.
227 0x4f, 0x63, 0x74, 0x20, 0x4e, 0x6f, 0x76, 0x20, // Oct.Nov.
228 0x44, 0x65, 0x63, 0x20, 0x30, 0x30, 0x3a, 0x30, // Dec.00.0
229 0x30, 0x3a, 0x30, 0x30, 0x20, 0x4d, 0x6f, 0x6e, // 0.00.Mon
230 0x2c, 0x20, 0x54, 0x75, 0x65, 0x2c, 0x20, 0x57, // ..Tue..W
231 0x65, 0x64, 0x2c, 0x20, 0x54, 0x68, 0x75, 0x2c, // ed..Thu.
232 0x20, 0x46, 0x72, 0x69, 0x2c, 0x20, 0x53, 0x61, // .Fri..Sa
233 0x74, 0x2c, 0x20, 0x53, 0x75, 0x6e, 0x2c, 0x20, // t..Sun..
234 0x47, 0x4d, 0x54, 0x63, 0x68, 0x75, 0x6e, 0x6b, // GMTchunk
235 0x65, 0x64, 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, // ed.text.
236 0x68, 0x74, 0x6d, 0x6c, 0x2c, 0x69, 0x6d, 0x61, // html.ima
237 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x2c, 0x69, // ge.png.i
238 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x67, // mage.jpg
239 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67, // .image.g
240 0x69, 0x66, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // if.appli
241 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // cation.x
242 0x6d, 0x6c, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // ml.appli
243 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // cation.x
244 0x68, 0x74, 0x6d, 0x6c, 0x2b, 0x78, 0x6d, 0x6c, // html.xml
245 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, // .text.pl
246 0x61, 0x69, 0x6e, 0x2c, 0x74, 0x65, 0x78, 0x74, // ain.text
247 0x2f, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, // .javascr
248 0x69, 0x70, 0x74, 0x2c, 0x70, 0x75, 0x62, 0x6c, // ipt.publ
249 0x69, 0x63, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, // icprivat
250 0x65, 0x6d, 0x61, 0x78, 0x2d, 0x61, 0x67, 0x65, // emax-age
251 0x3d, 0x67, 0x7a, 0x69, 0x70, 0x2c, 0x64, 0x65, // .gzip.de
252 0x66, 0x6c, 0x61, 0x74, 0x65, 0x2c, 0x73, 0x64, // flate.sd
253 0x63, 0x68, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // chcharse
254 0x74, 0x3d, 0x75, 0x74, 0x66, 0x2d, 0x38, 0x63, // t.utf-8c
255 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x3d, 0x69, // harset.i
256 0x73, 0x6f, 0x2d, 0x38, 0x38, 0x35, 0x39, 0x2d, // so-8859-
257 0x31, 0x2c, 0x75, 0x74, 0x66, 0x2d, 0x2c, 0x2a, // 1.utf-..
258 0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e // .enq.0.
260 const int kV3DictionarySize
= arraysize(kV3Dictionary
);
262 // The HTTP/2 connection header prefix, which must be the first bytes
263 // sent by the client upon starting an HTTP/2 connection, and which
264 // must be followed by a SETTINGS frame.
266 // Equivalent to the string "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
267 // (without the null terminator).
268 const char kHttp2ConnectionHeaderPrefix
[] = {
269 0x50, 0x52, 0x49, 0x20, 0x2a, 0x20, 0x48, 0x54, // PRI * HT
270 0x54, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x0d, 0x0a, // TP/2.0..
271 0x0d, 0x0a, 0x53, 0x4d, 0x0d, 0x0a, 0x0d, 0x0a // ..SM....
273 const int kHttp2ConnectionHeaderPrefixSize
=
274 arraysize(kHttp2ConnectionHeaderPrefix
);
276 const char kHttp2VersionString
[] = "HTTP/1.1";
278 // Types of SPDY frames.
289 CREDENTIAL
= 10, // No longer valid. Kept for identifiability.
293 // BLOCKED and ALTSVC are recognized extensions.
298 // Flags on data packets.
300 DATA_FLAG_NONE
= 0x00,
301 DATA_FLAG_FIN
= 0x01,
302 DATA_FLAG_END_SEGMENT
= 0x02,
303 DATA_FLAG_PADDED
= 0x08,
304 DATA_FLAG_COMPRESSED
= 0x20,
307 // Flags on control packets
308 enum SpdyControlFlags
{
309 CONTROL_FLAG_NONE
= 0x00,
310 CONTROL_FLAG_FIN
= 0x01,
311 CONTROL_FLAG_UNIDIRECTIONAL
= 0x02,
315 PING_FLAG_ACK
= 0x01,
318 // Used by HEADERS, PUSH_PROMISE, and CONTINUATION.
319 enum SpdyHeadersFlags
{
320 HEADERS_FLAG_END_SEGMENT
= 0x02,
321 HEADERS_FLAG_END_HEADERS
= 0x04,
322 HEADERS_FLAG_PADDED
= 0x08,
323 HEADERS_FLAG_PRIORITY
= 0x20,
326 enum SpdyPushPromiseFlags
{
327 PUSH_PROMISE_FLAG_END_PUSH_PROMISE
= 0x04,
328 PUSH_PROMISE_FLAG_PADDED
= 0x08,
331 // Flags on the SETTINGS control frame.
332 enum SpdySettingsControlFlags
{
333 SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS
= 0x01,
336 enum Http2SettingsControlFlags
{
337 SETTINGS_FLAG_ACK
= 0x01,
340 // Flags for settings within a SETTINGS frame.
341 enum SpdySettingsFlags
{
342 SETTINGS_FLAG_NONE
= 0x00,
343 SETTINGS_FLAG_PLEASE_PERSIST
= 0x01,
344 SETTINGS_FLAG_PERSISTED
= 0x02,
347 // List of known settings. Avoid changing these enum values, as persisted
348 // settings are keyed on them, and they are also exposed in net-internals.
349 enum SpdySettingsIds
{
350 SETTINGS_UPLOAD_BANDWIDTH
= 0x1,
351 SETTINGS_DOWNLOAD_BANDWIDTH
= 0x2,
352 // Network round trip time in milliseconds.
353 SETTINGS_ROUND_TRIP_TIME
= 0x3,
354 // The maximum number of simultaneous live streams in each direction.
355 SETTINGS_MAX_CONCURRENT_STREAMS
= 0x4,
356 // TCP congestion window in packets.
357 SETTINGS_CURRENT_CWND
= 0x5,
358 // Downstream byte retransmission rate in percentage.
359 SETTINGS_DOWNLOAD_RETRANS_RATE
= 0x6,
360 // Initial window size in bytes
361 SETTINGS_INITIAL_WINDOW_SIZE
= 0x7,
362 // HPACK header table maximum size.
363 SETTINGS_HEADER_TABLE_SIZE
= 0x8,
364 // Whether or not server push (PUSH_PROMISE) is enabled.
365 SETTINGS_ENABLE_PUSH
= 0x9,
366 // The size of the largest frame payload that a receiver is willing to accept.
367 SETTINGS_MAX_FRAME_SIZE
= 0xa,
368 // The maximum size of header list that the sender is prepared to accept.
369 SETTINGS_MAX_HEADER_LIST_SIZE
= 0xb,
372 // Status codes for RST_STREAM frames.
373 enum SpdyRstStreamStatus
{
374 RST_STREAM_INVALID
= 0,
375 RST_STREAM_PROTOCOL_ERROR
= 1,
376 RST_STREAM_INVALID_STREAM
= 2,
377 RST_STREAM_STREAM_CLOSED
= 2, // Equivalent to INVALID_STREAM
378 RST_STREAM_REFUSED_STREAM
= 3,
379 RST_STREAM_UNSUPPORTED_VERSION
= 4,
380 RST_STREAM_CANCEL
= 5,
381 RST_STREAM_INTERNAL_ERROR
= 6,
382 RST_STREAM_FLOW_CONTROL_ERROR
= 7,
383 RST_STREAM_STREAM_IN_USE
= 8,
384 RST_STREAM_STREAM_ALREADY_CLOSED
= 9,
385 RST_STREAM_INVALID_CREDENTIALS
= 10,
386 // FRAME_TOO_LARGE (defined by SPDY versions 3.1 and below), and
387 // FRAME_SIZE_ERROR (defined by HTTP/2) are mapped to the same internal
389 RST_STREAM_FRAME_TOO_LARGE
= 11,
390 RST_STREAM_FRAME_SIZE_ERROR
= 11,
391 RST_STREAM_SETTINGS_TIMEOUT
= 12,
392 RST_STREAM_CONNECT_ERROR
= 13,
393 RST_STREAM_ENHANCE_YOUR_CALM
= 14,
394 RST_STREAM_INADEQUATE_SECURITY
= 15,
395 RST_STREAM_HTTP_1_1_REQUIRED
= 16,
396 RST_STREAM_NUM_STATUS_CODES
= 17
399 // Status codes for GOAWAY frames.
400 enum SpdyGoAwayStatus
{
402 GOAWAY_NO_ERROR
= GOAWAY_OK
,
403 GOAWAY_PROTOCOL_ERROR
= 1,
404 GOAWAY_INTERNAL_ERROR
= 2,
405 GOAWAY_FLOW_CONTROL_ERROR
= 3,
406 GOAWAY_SETTINGS_TIMEOUT
= 4,
407 GOAWAY_STREAM_CLOSED
= 5,
408 GOAWAY_FRAME_SIZE_ERROR
= 6,
409 GOAWAY_REFUSED_STREAM
= 7,
411 GOAWAY_COMPRESSION_ERROR
= 9,
412 GOAWAY_CONNECT_ERROR
= 10,
413 GOAWAY_ENHANCE_YOUR_CALM
= 11,
414 GOAWAY_INADEQUATE_SECURITY
= 12,
415 GOAWAY_HTTP_1_1_REQUIRED
= 13
418 // A SPDY priority is a number between 0 and 7 (inclusive).
419 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a
420 // number between 0 and 3.
421 typedef uint8 SpdyPriority
;
423 typedef std::map
<std::string
, std::string
> SpdyNameValueBlock
;
425 typedef uint64 SpdyPingId
;
427 typedef std::string SpdyProtocolId
;
429 enum class SpdyHeaderValidatorType
{ REQUEST
, RESPONSE
};
431 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any,
432 // but is good to do anyway.
433 class NET_EXPORT_PRIVATE SpdyConstants
{
435 // Returns true if a given on-the-wire enumeration of a frame type is valid
436 // for a given protocol version, false otherwise.
437 static bool IsValidFrameType(SpdyMajorVersion version
, int frame_type_field
);
439 // Parses a frame type from an on-the-wire enumeration of a given protocol
441 // Behavior is undefined for invalid frame type fields; consumers should first
442 // use IsValidFrameType() to verify validity of frame type fields.
443 static SpdyFrameType
ParseFrameType(SpdyMajorVersion version
,
444 int frame_type_field
);
446 // Serializes a given frame type to the on-the-wire enumeration value for the
447 // given protocol version.
448 // Returns -1 on failure (I.E. Invalid frame type for the given version).
449 static int SerializeFrameType(SpdyMajorVersion version
,
450 SpdyFrameType frame_type
);
452 // Returns the frame type for non-control (i.e. data) frames
453 // in the given SPDY version.
454 static int DataFrameType(SpdyMajorVersion version
);
456 // Returns true if a given on-the-wire enumeration of a setting id is valid
457 // for a given protocol version, false otherwise.
458 static bool IsValidSettingId(SpdyMajorVersion version
, int setting_id_field
);
460 // Parses a setting id from an on-the-wire enumeration of a given protocol
462 // Behavior is undefined for invalid setting id fields; consumers should first
463 // use IsValidSettingId() to verify validity of setting id fields.
464 static SpdySettingsIds
ParseSettingId(SpdyMajorVersion version
,
465 int setting_id_field
);
467 // Serializes a given setting id to the on-the-wire enumeration value for the
468 // given protocol version.
469 // Returns -1 on failure (I.E. Invalid setting id for the given version).
470 static int SerializeSettingId(SpdyMajorVersion version
, SpdySettingsIds id
);
472 // Returns true if a given on-the-wire enumeration of a RST_STREAM status code
473 // is valid for a given protocol version, false otherwise.
474 static bool IsValidRstStreamStatus(SpdyMajorVersion version
,
475 int rst_stream_status_field
);
477 // Parses a RST_STREAM status code from an on-the-wire enumeration of a given
479 // Behavior is undefined for invalid RST_STREAM status code fields; consumers
480 // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM
481 // status code fields..
482 static SpdyRstStreamStatus
ParseRstStreamStatus(SpdyMajorVersion version
,
483 int rst_stream_status_field
);
485 // Serializes a given RST_STREAM status code to the on-the-wire enumeration
486 // value for the given protocol version.
487 // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given
489 static int SerializeRstStreamStatus(SpdyMajorVersion version
,
490 SpdyRstStreamStatus rst_stream_status
);
492 // Returns true if a given on-the-wire enumeration of a GOAWAY status code is
493 // valid for the given protocol version, false otherwise.
494 static bool IsValidGoAwayStatus(SpdyMajorVersion version
,
495 int goaway_status_field
);
497 // Parses a GOAWAY status from an on-the-wire enumeration of a given protocol
499 // Behavior is undefined for invalid GOAWAY status fields; consumers should
500 // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields.
501 static SpdyGoAwayStatus
ParseGoAwayStatus(SpdyMajorVersion version
,
502 int goaway_status_field
);
504 // Serializes a given GOAWAY status to the on-the-wire enumeration value for
505 // the given protocol version.
506 // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version).
507 static int SerializeGoAwayStatus(SpdyMajorVersion version
,
508 SpdyGoAwayStatus status
);
510 // Size, in bytes, of the data frame header. Future versions of SPDY
511 // will likely vary this, so we allow for the flexibility of a function call
512 // for this value as opposed to a constant.
513 static size_t GetDataFrameMinimumSize(SpdyMajorVersion version
);
515 // Size, in bytes, of the control frame header.
516 static size_t GetControlFrameHeaderSize(SpdyMajorVersion version
);
518 static size_t GetPrefixLength(SpdyFrameType type
, SpdyMajorVersion version
);
520 static size_t GetFrameMaximumSize(SpdyMajorVersion version
);
522 // Returns the size of a header block size field. Valid only for SPDY
524 static size_t GetSizeOfSizeField(SpdyMajorVersion version
);
526 // Returns the size (in bytes) of a wire setting ID and value.
527 static size_t GetSettingSize(SpdyMajorVersion version
);
529 // Initial window size for a stream in bytes.
530 static int32
GetInitialStreamWindowSize(SpdyMajorVersion version
);
532 // Initial window size for a session in bytes.
533 static int32
GetInitialSessionWindowSize(SpdyMajorVersion version
);
535 static SpdyMajorVersion
ParseMajorVersion(int version_number
);
537 static int SerializeMajorVersion(SpdyMajorVersion version
);
539 static std::string
GetVersionString(SpdyMajorVersion version
);
543 typedef SpdyFrame SpdySerializedFrame
;
545 class SpdyFrameVisitor
;
547 // Intermediate representation for SPDY frames.
548 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is
550 class NET_EXPORT_PRIVATE SpdyFrameIR
{
552 virtual ~SpdyFrameIR() {}
554 virtual void Visit(SpdyFrameVisitor
* visitor
) const = 0;
560 DISALLOW_COPY_AND_ASSIGN(SpdyFrameIR
);
563 // Abstract class intended to be inherited by IRs that have a stream associated
565 class NET_EXPORT_PRIVATE SpdyFrameWithStreamIdIR
: public SpdyFrameIR
{
567 ~SpdyFrameWithStreamIdIR() override
{}
568 SpdyStreamId
stream_id() const { return stream_id_
; }
569 void set_stream_id(SpdyStreamId stream_id
) {
570 DCHECK_EQ(0u, stream_id
& ~kStreamIdMask
);
571 stream_id_
= stream_id
;
575 explicit SpdyFrameWithStreamIdIR(SpdyStreamId stream_id
) {
576 set_stream_id(stream_id
);
580 SpdyStreamId stream_id_
;
582 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithStreamIdIR
);
585 // Abstract class intended to be inherited by IRs that have the option of a FIN
586 // flag. Implies SpdyFrameWithStreamIdIR.
587 class NET_EXPORT_PRIVATE SpdyFrameWithFinIR
: public SpdyFrameWithStreamIdIR
{
589 ~SpdyFrameWithFinIR() override
{}
590 bool fin() const { return fin_
; }
591 void set_fin(bool fin
) { fin_
= fin
; }
594 explicit SpdyFrameWithFinIR(SpdyStreamId stream_id
)
595 : SpdyFrameWithStreamIdIR(stream_id
),
601 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithFinIR
);
604 // Abstract class intended to be inherited by IRs that contain a name-value
605 // block. Implies SpdyFrameWithFinIR.
606 class NET_EXPORT_PRIVATE SpdyFrameWithNameValueBlockIR
607 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR
) {
609 const SpdyNameValueBlock
& name_value_block() const {
610 return name_value_block_
;
612 void set_name_value_block(const SpdyNameValueBlock
& name_value_block
) {
614 name_value_block_
= name_value_block
;
616 void SetHeader(base::StringPiece name
, base::StringPiece value
) {
617 name_value_block_
[name
.as_string()] = value
.as_string();
619 SpdyNameValueBlock
* mutable_name_value_block() {
620 return &name_value_block_
;
624 explicit SpdyFrameWithNameValueBlockIR(SpdyStreamId stream_id
);
625 ~SpdyFrameWithNameValueBlockIR() override
;
628 SpdyNameValueBlock name_value_block_
;
630 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithNameValueBlockIR
);
633 class NET_EXPORT_PRIVATE SpdyDataIR
634 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR
) {
636 // Performs deep copy on data.
637 SpdyDataIR(SpdyStreamId stream_id
, 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
);
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(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(base::StringPiece data
) {
670 void Visit(SpdyFrameVisitor
* visitor
) const override
;
673 // Used to store data that this SpdyDataIR should own.
674 scoped_ptr
<std::string
> data_store_
;
675 base::StringPiece data_
;
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
{
687 explicit SpdySynStreamIR(SpdyStreamId stream_id
)
688 : SpdyFrameWithNameValueBlockIR(stream_id
),
689 associated_to_stream_id_(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
;
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
{
717 explicit SpdySynReplyIR(SpdyStreamId stream_id
)
718 : SpdyFrameWithNameValueBlockIR(stream_id
) {}
720 void Visit(SpdyFrameVisitor
* visitor
) const override
;
723 DISALLOW_COPY_AND_ASSIGN(SpdySynReplyIR
);
726 class NET_EXPORT_PRIVATE SpdyRstStreamIR
: public SpdyFrameWithStreamIdIR
{
728 SpdyRstStreamIR(SpdyStreamId stream_id
, SpdyRstStreamStatus status
,
729 base::StringPiece description
);
731 ~SpdyRstStreamIR() override
;
733 SpdyRstStreamStatus
status() const {
736 void set_status(SpdyRstStreamStatus status
) {
740 base::StringPiece
description() const { return description_
; }
742 void Visit(SpdyFrameVisitor
* visitor
) const override
;
745 SpdyRstStreamStatus status_
;
746 base::StringPiece description_
;
748 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR
);
751 class NET_EXPORT_PRIVATE SpdySettingsIR
: public SpdyFrameIR
{
753 // Associates flags with a value.
755 Value() : persist_value(false),
762 typedef std::map
<SpdySettingsIds
, Value
> ValueMap
;
766 ~SpdySettingsIR() override
;
768 // Overwrites as appropriate.
769 const ValueMap
& values() const { return values_
; }
770 void AddSetting(SpdySettingsIds id
,
774 values_
[id
].persist_value
= persist_value
;
775 values_
[id
].persisted
= persisted
;
776 values_
[id
].value
= value
;
779 bool clear_settings() const { return clear_settings_
; }
780 bool is_ack() const { return is_ack_
; }
781 void set_is_ack(bool is_ack
) {
785 void Visit(SpdyFrameVisitor
* visitor
) const override
;
789 bool clear_settings_
;
792 DISALLOW_COPY_AND_ASSIGN(SpdySettingsIR
);
795 class NET_EXPORT_PRIVATE SpdyPingIR
: public SpdyFrameIR
{
797 explicit SpdyPingIR(SpdyPingId id
) : id_(id
), is_ack_(false) {}
798 SpdyPingId
id() const { return id_
; }
800 // ACK logic is valid only for SPDY versions 4 and above.
801 bool is_ack() const { return is_ack_
; }
802 void set_is_ack(bool is_ack
) { is_ack_
= is_ack
; }
804 void Visit(SpdyFrameVisitor
* visitor
) const override
;
810 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR
);
813 class NET_EXPORT_PRIVATE SpdyGoAwayIR
: public SpdyFrameIR
{
815 SpdyGoAwayIR(SpdyStreamId last_good_stream_id
,
816 SpdyGoAwayStatus status
,
817 base::StringPiece description
);
818 ~SpdyGoAwayIR() override
;
819 SpdyStreamId
last_good_stream_id() const { return last_good_stream_id_
; }
820 void set_last_good_stream_id(SpdyStreamId last_good_stream_id
) {
821 DCHECK_LE(0u, last_good_stream_id
);
822 DCHECK_EQ(0u, last_good_stream_id
& ~kStreamIdMask
);
823 last_good_stream_id_
= last_good_stream_id
;
825 SpdyGoAwayStatus
status() const { return status_
; }
826 void set_status(SpdyGoAwayStatus status
) {
827 // TODO(hkhalil): Check valid ranges of status?
831 const base::StringPiece
& description() const;
833 void Visit(SpdyFrameVisitor
* visitor
) const override
;
836 SpdyStreamId last_good_stream_id_
;
837 SpdyGoAwayStatus status_
;
838 const base::StringPiece description_
;
840 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR
);
843 class NET_EXPORT_PRIVATE SpdyHeadersIR
: public SpdyFrameWithNameValueBlockIR
{
845 explicit SpdyHeadersIR(SpdyStreamId stream_id
)
846 : SpdyFrameWithNameValueBlockIR(stream_id
) {}
848 void Visit(SpdyFrameVisitor
* visitor
) const override
;
850 bool has_priority() const { return has_priority_
; }
851 void set_has_priority(bool has_priority
) { has_priority_
= has_priority
; }
852 uint32
priority() const { return priority_
; }
853 void set_priority(SpdyPriority priority
) { priority_
= priority
; }
854 SpdyStreamId
parent_stream_id() const { return parent_stream_id_
; }
855 void set_parent_stream_id(SpdyStreamId id
) { parent_stream_id_
= id
; }
856 bool exclusive() const { return exclusive_
; }
857 void set_exclusive(bool exclusive
) { exclusive_
= exclusive
; }
858 bool padded() const { return padded_
; }
859 int padding_payload_len() const { return padding_payload_len_
; }
860 void set_padding_len(int padding_len
) {
861 DCHECK_GT(padding_len
, 0);
862 DCHECK_LE(padding_len
, kPaddingSizePerFrame
);
864 // The pad field takes one octet on the wire.
865 padding_payload_len_
= padding_len
- 1;
869 bool has_priority_
= false;
871 uint32 priority_
= 0;
872 SpdyStreamId parent_stream_id_
= 0;
873 bool exclusive_
= false;
874 bool padded_
= false;
875 int padding_payload_len_
= 0;
877 DISALLOW_COPY_AND_ASSIGN(SpdyHeadersIR
);
880 class NET_EXPORT_PRIVATE SpdyWindowUpdateIR
: public SpdyFrameWithStreamIdIR
{
882 SpdyWindowUpdateIR(SpdyStreamId stream_id
, int32 delta
)
883 : SpdyFrameWithStreamIdIR(stream_id
) {
886 int32
delta() const { return delta_
; }
887 void set_delta(int32 delta
) {
889 DCHECK_LE(delta
, kSpdyMaximumWindowSize
);
893 void Visit(SpdyFrameVisitor
* visitor
) const override
;
898 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateIR
);
901 class NET_EXPORT_PRIVATE SpdyBlockedIR
902 : public NON_EXPORTED_BASE(SpdyFrameWithStreamIdIR
) {
904 explicit SpdyBlockedIR(SpdyStreamId stream_id
)
905 : SpdyFrameWithStreamIdIR(stream_id
) {}
907 void Visit(SpdyFrameVisitor
* visitor
) const override
;
910 DISALLOW_COPY_AND_ASSIGN(SpdyBlockedIR
);
913 class NET_EXPORT_PRIVATE SpdyPushPromiseIR
914 : public SpdyFrameWithNameValueBlockIR
{
916 SpdyPushPromiseIR(SpdyStreamId stream_id
, SpdyStreamId promised_stream_id
)
917 : SpdyFrameWithNameValueBlockIR(stream_id
),
918 promised_stream_id_(promised_stream_id
),
920 padding_payload_len_(0) {}
921 SpdyStreamId
promised_stream_id() const { return promised_stream_id_
; }
923 void Visit(SpdyFrameVisitor
* visitor
) const override
;
925 bool padded() const { return padded_
; }
926 int padding_payload_len() const { return padding_payload_len_
; }
927 void set_padding_len(int padding_len
) {
928 DCHECK_GT(padding_len
, 0);
929 DCHECK_LE(padding_len
, kPaddingSizePerFrame
);
931 // The pad field takes one octet on the wire.
932 padding_payload_len_
= padding_len
- 1;
936 SpdyStreamId promised_stream_id_
;
939 int padding_payload_len_
;
941 DISALLOW_COPY_AND_ASSIGN(SpdyPushPromiseIR
);
944 // TODO(jgraettinger): This representation needs review. SpdyContinuationIR
945 // needs to frame a portion of a single, arbitrarily-broken encoded buffer.
946 class NET_EXPORT_PRIVATE SpdyContinuationIR
947 : public SpdyFrameWithNameValueBlockIR
{
949 explicit SpdyContinuationIR(SpdyStreamId stream_id
)
950 : SpdyFrameWithNameValueBlockIR(stream_id
),
951 end_headers_(false) {}
953 void Visit(SpdyFrameVisitor
* visitor
) const override
;
955 bool end_headers() const { return end_headers_
; }
956 void set_end_headers(bool end_headers
) {end_headers_
= end_headers
;}
960 DISALLOW_COPY_AND_ASSIGN(SpdyContinuationIR
);
963 class NET_EXPORT_PRIVATE SpdyAltSvcIR
: public SpdyFrameWithStreamIdIR
{
965 explicit SpdyAltSvcIR(SpdyStreamId stream_id
);
966 ~SpdyAltSvcIR() override
;
968 std::string
origin() const { return origin_
; }
969 const SpdyAltSvcWireFormat::AlternativeServiceVector
& altsvc_vector() const {
970 return altsvc_vector_
;
973 void set_origin(const std::string origin
) { origin_
= origin
; }
974 void add_altsvc(const SpdyAltSvcWireFormat::AlternativeService
& altsvc
) {
975 altsvc_vector_
.push_back(altsvc
);
978 void Visit(SpdyFrameVisitor
* visitor
) const override
;
982 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector_
;
983 DISALLOW_COPY_AND_ASSIGN(SpdyAltSvcIR
);
986 class NET_EXPORT_PRIVATE SpdyPriorityIR
: public SpdyFrameWithStreamIdIR
{
988 explicit SpdyPriorityIR(SpdyStreamId stream_id
)
989 : SpdyFrameWithStreamIdIR(stream_id
),
990 parent_stream_id_(0),
993 SpdyPriorityIR(SpdyStreamId stream_id
,
994 SpdyStreamId parent_stream_id
,
997 : SpdyFrameWithStreamIdIR(stream_id
),
998 parent_stream_id_(parent_stream_id
),
1000 exclusive_(exclusive
) {}
1001 SpdyStreamId
parent_stream_id() const { return parent_stream_id_
; }
1002 void set_parent_stream_id(SpdyStreamId id
) { parent_stream_id_
= id
; }
1003 uint8
weight() const { return weight_
; }
1004 void set_weight(uint8 weight
) { weight_
= weight
; }
1005 bool exclusive() const { return exclusive_
; }
1006 void set_exclusive(bool exclusive
) { exclusive_
= exclusive
; }
1008 void Visit(SpdyFrameVisitor
* visitor
) const override
;
1011 SpdyStreamId parent_stream_id_
;
1014 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR
);
1017 // -------------------------------------------------------------------------
1018 // Wrapper classes for various SPDY frames.
1020 // All Spdy Frame types derive from this SpdyFrame class.
1023 // Create a SpdyFrame using a pre-created buffer.
1024 // If |owns_buffer| is true, this class takes ownership of the buffer
1025 // and will delete it on cleanup. The buffer must have been created using
1027 // If |owns_buffer| is false, the caller retains ownership of the buffer and
1028 // is responsible for making sure the buffer outlives this frame. In other
1029 // words, this class does NOT create a copy of the buffer.
1030 SpdyFrame(char* data
, size_t size
, bool owns_buffer
)
1033 owns_buffer_(owns_buffer
) {
1044 // Provides access to the frame bytes, which is a buffer containing
1045 // the frame packed as expected for sending over the wire.
1046 char* data() const { return frame_
; }
1048 // Returns the actual size of the underlying buffer.
1049 size_t size() const { return size_
; }
1057 DISALLOW_COPY_AND_ASSIGN(SpdyFrame
);
1060 // This interface is for classes that want to process SpdyFrameIRs without
1061 // having to know what type they are. An instance of this interface can be
1062 // passed to a SpdyFrameIR's Visit method, and the appropriate type-specific
1063 // method of this class will be called.
1064 class SpdyFrameVisitor
{
1066 virtual void VisitSynStream(const SpdySynStreamIR
& syn_stream
) = 0;
1067 virtual void VisitSynReply(const SpdySynReplyIR
& syn_reply
) = 0;
1068 virtual void VisitRstStream(const SpdyRstStreamIR
& rst_stream
) = 0;
1069 virtual void VisitSettings(const SpdySettingsIR
& settings
) = 0;
1070 virtual void VisitPing(const SpdyPingIR
& ping
) = 0;
1071 virtual void VisitGoAway(const SpdyGoAwayIR
& goaway
) = 0;
1072 virtual void VisitHeaders(const SpdyHeadersIR
& headers
) = 0;
1073 virtual void VisitWindowUpdate(const SpdyWindowUpdateIR
& window_update
) = 0;
1074 virtual void VisitBlocked(const SpdyBlockedIR
& blocked
) = 0;
1075 virtual void VisitPushPromise(const SpdyPushPromiseIR
& push_promise
) = 0;
1076 virtual void VisitContinuation(const SpdyContinuationIR
& continuation
) = 0;
1077 virtual void VisitAltSvc(const SpdyAltSvcIR
& altsvc
) = 0;
1078 virtual void VisitPriority(const SpdyPriorityIR
& priority
) = 0;
1079 virtual void VisitData(const SpdyDataIR
& data
) = 0;
1082 SpdyFrameVisitor() {}
1083 virtual ~SpdyFrameVisitor() {}
1086 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor
);
1091 #endif // NET_SPDY_SPDY_PROTOCOL_H_