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_
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_alt_svc_wire_format.h"
27 #include "net/spdy/spdy_bitmasks.h"
31 // The major versions of SPDY. Major version differences indicate
32 // framer-layer incompatibility, as opposed to minor version numbers
33 // which indicate application-layer incompatibility. Do not rely on
34 // the mapping from enum value SPDYn to the integer n.
35 enum SpdyMajorVersion
{
37 SPDY_MIN_VERSION
= SPDY2
,
41 SPDY_MAX_VERSION
= SPDY4
44 // A SPDY stream id is a 31 bit entity.
45 typedef uint32 SpdyStreamId
;
47 // Specifies the stream ID used to denote the current session (for
49 const SpdyStreamId kSessionFlowControlStreamId
= 0;
51 // The maxmium possible control frame size allowed by the spec.
52 const int32 kSpdyMaxControlFrameSize
= (1 << 24) - 1;
54 // The maximum control frame size we accept.
55 const int32 kControlFrameSizeLimit
= 1 << 14;
57 // Maximum window size for a Spdy stream or session.
58 const int32 kSpdyMaximumWindowSize
= 0x7FFFFFFF; // Max signed 32bit int
60 // Maximum padding size in octets for one DATA or HEADERS or PUSH_PROMISE frame.
61 const int32 kPaddingSizePerFrame
= 256;
64 // This is just a hacked dictionary to use for shrinking HTTP-like headers.
65 const char kV2Dictionary
[] =
66 "optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-"
67 "languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi"
68 "f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser"
69 "-agent10010120020120220320420520630030130230330430530630740040140240340440"
70 "5406407408409410411412413414415416417500501502503504505accept-rangesageeta"
71 "glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic"
72 "ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran"
73 "sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati"
74 "oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo"
75 "ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe"
76 "pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic"
77 "ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1"
79 const int kV2DictionarySize
= arraysize(kV2Dictionary
);
82 const char kV3Dictionary
[] = {
83 0x00, 0x00, 0x00, 0x07, 0x6f, 0x70, 0x74, 0x69, // ....opti
84 0x6f, 0x6e, 0x73, 0x00, 0x00, 0x00, 0x04, 0x68, // ons....h
85 0x65, 0x61, 0x64, 0x00, 0x00, 0x00, 0x04, 0x70, // ead....p
86 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x03, 0x70, // ost....p
87 0x75, 0x74, 0x00, 0x00, 0x00, 0x06, 0x64, 0x65, // ut....de
88 0x6c, 0x65, 0x74, 0x65, 0x00, 0x00, 0x00, 0x05, // lete....
89 0x74, 0x72, 0x61, 0x63, 0x65, 0x00, 0x00, 0x00, // trace...
90 0x06, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x00, // .accept.
91 0x00, 0x00, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70, // ...accep
92 0x74, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // t-charse
93 0x74, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x63, 0x63, // t....acc
94 0x65, 0x70, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // ept-enco
95 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x0f, // ding....
96 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x6c, // accept-l
97 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x00, // anguage.
98 0x00, 0x00, 0x0d, 0x61, 0x63, 0x63, 0x65, 0x70, // ...accep
99 0x74, 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x73, // t-ranges
100 0x00, 0x00, 0x00, 0x03, 0x61, 0x67, 0x65, 0x00, // ....age.
101 0x00, 0x00, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77, // ...allow
102 0x00, 0x00, 0x00, 0x0d, 0x61, 0x75, 0x74, 0x68, // ....auth
103 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, // orizatio
104 0x6e, 0x00, 0x00, 0x00, 0x0d, 0x63, 0x61, 0x63, // n....cac
105 0x68, 0x65, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, // he-contr
106 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f, // ol....co
107 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, // nnection
108 0x00, 0x00, 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, // ....cont
109 0x65, 0x6e, 0x74, 0x2d, 0x62, 0x61, 0x73, 0x65, // ent-base
110 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, 0x6e, 0x74, // ....cont
111 0x65, 0x6e, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f, // ent-enco
112 0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, // ding....
113 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, // content-
114 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, // language
115 0x00, 0x00, 0x00, 0x0e, 0x63, 0x6f, 0x6e, 0x74, // ....cont
116 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x65, 0x6e, 0x67, // ent-leng
117 0x74, 0x68, 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, // th....co
118 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x6f, // ntent-lo
119 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, // cation..
120 0x00, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // ..conten
121 0x74, 0x2d, 0x6d, 0x64, 0x35, 0x00, 0x00, 0x00, // t-md5...
122 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, // .content
123 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, // -range..
124 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, // ..conten
125 0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00, // t-type..
126 0x00, 0x04, 0x64, 0x61, 0x74, 0x65, 0x00, 0x00, // ..date..
127 0x00, 0x04, 0x65, 0x74, 0x61, 0x67, 0x00, 0x00, // ..etag..
128 0x00, 0x06, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, // ..expect
129 0x00, 0x00, 0x00, 0x07, 0x65, 0x78, 0x70, 0x69, // ....expi
130 0x72, 0x65, 0x73, 0x00, 0x00, 0x00, 0x04, 0x66, // res....f
131 0x72, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x04, 0x68, // rom....h
132 0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x08, 0x69, // ost....i
133 0x66, 0x2d, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, // f-match.
134 0x00, 0x00, 0x11, 0x69, 0x66, 0x2d, 0x6d, 0x6f, // ...if-mo
135 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x2d, 0x73, // dified-s
136 0x69, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x0d, // ince....
137 0x69, 0x66, 0x2d, 0x6e, 0x6f, 0x6e, 0x65, 0x2d, // if-none-
138 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, 0x00, 0x00, // match...
139 0x08, 0x69, 0x66, 0x2d, 0x72, 0x61, 0x6e, 0x67, // .if-rang
140 0x65, 0x00, 0x00, 0x00, 0x13, 0x69, 0x66, 0x2d, // e....if-
141 0x75, 0x6e, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, // unmodifi
142 0x65, 0x64, 0x2d, 0x73, 0x69, 0x6e, 0x63, 0x65, // ed-since
143 0x00, 0x00, 0x00, 0x0d, 0x6c, 0x61, 0x73, 0x74, // ....last
144 0x2d, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, // -modifie
145 0x64, 0x00, 0x00, 0x00, 0x08, 0x6c, 0x6f, 0x63, // d....loc
146 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, // ation...
147 0x0c, 0x6d, 0x61, 0x78, 0x2d, 0x66, 0x6f, 0x72, // .max-for
148 0x77, 0x61, 0x72, 0x64, 0x73, 0x00, 0x00, 0x00, // wards...
149 0x06, 0x70, 0x72, 0x61, 0x67, 0x6d, 0x61, 0x00, // .pragma.
150 0x00, 0x00, 0x12, 0x70, 0x72, 0x6f, 0x78, 0x79, // ...proxy
151 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, // -authent
152 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, // icate...
153 0x13, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2d, 0x61, // .proxy-a
154 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, // uthoriza
155 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, // tion....
156 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, 0x00, // range...
157 0x07, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, // .referer
158 0x00, 0x00, 0x00, 0x0b, 0x72, 0x65, 0x74, 0x72, // ....retr
159 0x79, 0x2d, 0x61, 0x66, 0x74, 0x65, 0x72, 0x00, // y-after.
160 0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, // ...serve
161 0x72, 0x00, 0x00, 0x00, 0x02, 0x74, 0x65, 0x00, // r....te.
162 0x00, 0x00, 0x07, 0x74, 0x72, 0x61, 0x69, 0x6c, // ...trail
163 0x65, 0x72, 0x00, 0x00, 0x00, 0x11, 0x74, 0x72, // er....tr
164 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x2d, 0x65, // ansfer-e
165 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x00, // ncoding.
166 0x00, 0x00, 0x07, 0x75, 0x70, 0x67, 0x72, 0x61, // ...upgra
167 0x64, 0x65, 0x00, 0x00, 0x00, 0x0a, 0x75, 0x73, // de....us
168 0x65, 0x72, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74, // er-agent
169 0x00, 0x00, 0x00, 0x04, 0x76, 0x61, 0x72, 0x79, // ....vary
170 0x00, 0x00, 0x00, 0x03, 0x76, 0x69, 0x61, 0x00, // ....via.
171 0x00, 0x00, 0x07, 0x77, 0x61, 0x72, 0x6e, 0x69, // ...warni
172 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, 0x77, 0x77, // ng....ww
173 0x77, 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, // w-authen
174 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, // ticate..
175 0x00, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, // ..method
176 0x00, 0x00, 0x00, 0x03, 0x67, 0x65, 0x74, 0x00, // ....get.
177 0x00, 0x00, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, // ...statu
178 0x73, 0x00, 0x00, 0x00, 0x06, 0x32, 0x30, 0x30, // s....200
179 0x20, 0x4f, 0x4b, 0x00, 0x00, 0x00, 0x07, 0x76, // .OK....v
180 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, 0x00, // ersion..
181 0x00, 0x08, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, // ..HTTP.1
182 0x2e, 0x31, 0x00, 0x00, 0x00, 0x03, 0x75, 0x72, // .1....ur
183 0x6c, 0x00, 0x00, 0x00, 0x06, 0x70, 0x75, 0x62, // l....pub
184 0x6c, 0x69, 0x63, 0x00, 0x00, 0x00, 0x0a, 0x73, // lic....s
185 0x65, 0x74, 0x2d, 0x63, 0x6f, 0x6f, 0x6b, 0x69, // et-cooki
186 0x65, 0x00, 0x00, 0x00, 0x0a, 0x6b, 0x65, 0x65, // e....kee
187 0x70, 0x2d, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x00, // p-alive.
188 0x00, 0x00, 0x06, 0x6f, 0x72, 0x69, 0x67, 0x69, // ...origi
189 0x6e, 0x31, 0x30, 0x30, 0x31, 0x30, 0x31, 0x32, // n1001012
190 0x30, 0x31, 0x32, 0x30, 0x32, 0x32, 0x30, 0x35, // 01202205
191 0x32, 0x30, 0x36, 0x33, 0x30, 0x30, 0x33, 0x30, // 20630030
192 0x32, 0x33, 0x30, 0x33, 0x33, 0x30, 0x34, 0x33, // 23033043
193 0x30, 0x35, 0x33, 0x30, 0x36, 0x33, 0x30, 0x37, // 05306307
194 0x34, 0x30, 0x32, 0x34, 0x30, 0x35, 0x34, 0x30, // 40240540
195 0x36, 0x34, 0x30, 0x37, 0x34, 0x30, 0x38, 0x34, // 64074084
196 0x30, 0x39, 0x34, 0x31, 0x30, 0x34, 0x31, 0x31, // 09410411
197 0x34, 0x31, 0x32, 0x34, 0x31, 0x33, 0x34, 0x31, // 41241341
198 0x34, 0x34, 0x31, 0x35, 0x34, 0x31, 0x36, 0x34, // 44154164
199 0x31, 0x37, 0x35, 0x30, 0x32, 0x35, 0x30, 0x34, // 17502504
200 0x35, 0x30, 0x35, 0x32, 0x30, 0x33, 0x20, 0x4e, // 505203.N
201 0x6f, 0x6e, 0x2d, 0x41, 0x75, 0x74, 0x68, 0x6f, // on-Autho
202 0x72, 0x69, 0x74, 0x61, 0x74, 0x69, 0x76, 0x65, // ritative
203 0x20, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, // .Informa
204 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x30, 0x34, 0x20, // tion204.
205 0x4e, 0x6f, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x65, // No.Conte
206 0x6e, 0x74, 0x33, 0x30, 0x31, 0x20, 0x4d, 0x6f, // nt301.Mo
207 0x76, 0x65, 0x64, 0x20, 0x50, 0x65, 0x72, 0x6d, // ved.Perm
208 0x61, 0x6e, 0x65, 0x6e, 0x74, 0x6c, 0x79, 0x34, // anently4
209 0x30, 0x30, 0x20, 0x42, 0x61, 0x64, 0x20, 0x52, // 00.Bad.R
210 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x34, 0x30, // equest40
211 0x31, 0x20, 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68, // 1.Unauth
212 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64, 0x34, 0x30, // orized40
213 0x33, 0x20, 0x46, 0x6f, 0x72, 0x62, 0x69, 0x64, // 3.Forbid
214 0x64, 0x65, 0x6e, 0x34, 0x30, 0x34, 0x20, 0x4e, // den404.N
215 0x6f, 0x74, 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, // ot.Found
216 0x35, 0x30, 0x30, 0x20, 0x49, 0x6e, 0x74, 0x65, // 500.Inte
217 0x72, 0x6e, 0x61, 0x6c, 0x20, 0x53, 0x65, 0x72, // rnal.Ser
218 0x76, 0x65, 0x72, 0x20, 0x45, 0x72, 0x72, 0x6f, // ver.Erro
219 0x72, 0x35, 0x30, 0x31, 0x20, 0x4e, 0x6f, 0x74, // r501.Not
220 0x20, 0x49, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65, // .Impleme
221 0x6e, 0x74, 0x65, 0x64, 0x35, 0x30, 0x33, 0x20, // nted503.
222 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, // Service.
223 0x55, 0x6e, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, // Unavaila
224 0x62, 0x6c, 0x65, 0x4a, 0x61, 0x6e, 0x20, 0x46, // bleJan.F
225 0x65, 0x62, 0x20, 0x4d, 0x61, 0x72, 0x20, 0x41, // eb.Mar.A
226 0x70, 0x72, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x4a, // pr.May.J
227 0x75, 0x6e, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x41, // un.Jul.A
228 0x75, 0x67, 0x20, 0x53, 0x65, 0x70, 0x74, 0x20, // ug.Sept.
229 0x4f, 0x63, 0x74, 0x20, 0x4e, 0x6f, 0x76, 0x20, // Oct.Nov.
230 0x44, 0x65, 0x63, 0x20, 0x30, 0x30, 0x3a, 0x30, // Dec.00.0
231 0x30, 0x3a, 0x30, 0x30, 0x20, 0x4d, 0x6f, 0x6e, // 0.00.Mon
232 0x2c, 0x20, 0x54, 0x75, 0x65, 0x2c, 0x20, 0x57, // ..Tue..W
233 0x65, 0x64, 0x2c, 0x20, 0x54, 0x68, 0x75, 0x2c, // ed..Thu.
234 0x20, 0x46, 0x72, 0x69, 0x2c, 0x20, 0x53, 0x61, // .Fri..Sa
235 0x74, 0x2c, 0x20, 0x53, 0x75, 0x6e, 0x2c, 0x20, // t..Sun..
236 0x47, 0x4d, 0x54, 0x63, 0x68, 0x75, 0x6e, 0x6b, // GMTchunk
237 0x65, 0x64, 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, // ed.text.
238 0x68, 0x74, 0x6d, 0x6c, 0x2c, 0x69, 0x6d, 0x61, // html.ima
239 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x2c, 0x69, // ge.png.i
240 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x67, // mage.jpg
241 0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67, // .image.g
242 0x69, 0x66, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // if.appli
243 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // cation.x
244 0x6d, 0x6c, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69, // ml.appli
245 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78, // cation.x
246 0x68, 0x74, 0x6d, 0x6c, 0x2b, 0x78, 0x6d, 0x6c, // html.xml
247 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c, // .text.pl
248 0x61, 0x69, 0x6e, 0x2c, 0x74, 0x65, 0x78, 0x74, // ain.text
249 0x2f, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, // .javascr
250 0x69, 0x70, 0x74, 0x2c, 0x70, 0x75, 0x62, 0x6c, // ipt.publ
251 0x69, 0x63, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, // icprivat
252 0x65, 0x6d, 0x61, 0x78, 0x2d, 0x61, 0x67, 0x65, // emax-age
253 0x3d, 0x67, 0x7a, 0x69, 0x70, 0x2c, 0x64, 0x65, // .gzip.de
254 0x66, 0x6c, 0x61, 0x74, 0x65, 0x2c, 0x73, 0x64, // flate.sd
255 0x63, 0x68, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, // chcharse
256 0x74, 0x3d, 0x75, 0x74, 0x66, 0x2d, 0x38, 0x63, // t.utf-8c
257 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x3d, 0x69, // harset.i
258 0x73, 0x6f, 0x2d, 0x38, 0x38, 0x35, 0x39, 0x2d, // so-8859-
259 0x31, 0x2c, 0x75, 0x74, 0x66, 0x2d, 0x2c, 0x2a, // 1.utf-..
260 0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e // .enq.0.
262 const int kV3DictionarySize
= arraysize(kV3Dictionary
);
264 // The HTTP/2 connection header prefix, which must be the first bytes
265 // sent by the client upon starting an HTTP/2 connection, and which
266 // must be followed by a SETTINGS frame.
268 // Equivalent to the string "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
269 // (without the null terminator).
270 const char kHttp2ConnectionHeaderPrefix
[] = {
271 0x50, 0x52, 0x49, 0x20, 0x2a, 0x20, 0x48, 0x54, // PRI * HT
272 0x54, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x0d, 0x0a, // TP/2.0..
273 0x0d, 0x0a, 0x53, 0x4d, 0x0d, 0x0a, 0x0d, 0x0a // ..SM....
275 const int kHttp2ConnectionHeaderPrefixSize
=
276 arraysize(kHttp2ConnectionHeaderPrefix
);
278 const char kHttp2VersionString
[] = "HTTP/1.1";
280 // Types of SPDY frames.
291 CREDENTIAL
= 10, // No longer valid. Kept for identifiability.
295 // BLOCKED and ALTSVC are recognized extensions.
300 // Flags on data packets.
302 DATA_FLAG_NONE
= 0x00,
303 DATA_FLAG_FIN
= 0x01,
304 DATA_FLAG_END_SEGMENT
= 0x02,
305 DATA_FLAG_PADDED
= 0x08,
306 DATA_FLAG_COMPRESSED
= 0x20,
309 // Flags on control packets
310 enum SpdyControlFlags
{
311 CONTROL_FLAG_NONE
= 0x00,
312 CONTROL_FLAG_FIN
= 0x01,
313 CONTROL_FLAG_UNIDIRECTIONAL
= 0x02,
317 PING_FLAG_ACK
= 0x01,
320 // Used by HEADERS, PUSH_PROMISE, and CONTINUATION.
321 enum SpdyHeadersFlags
{
322 HEADERS_FLAG_END_SEGMENT
= 0x02,
323 HEADERS_FLAG_END_HEADERS
= 0x04,
324 HEADERS_FLAG_PADDED
= 0x08,
325 HEADERS_FLAG_PRIORITY
= 0x20,
328 enum SpdyPushPromiseFlags
{
329 PUSH_PROMISE_FLAG_END_PUSH_PROMISE
= 0x04,
330 PUSH_PROMISE_FLAG_PADDED
= 0x08,
333 // Flags on the SETTINGS control frame.
334 enum SpdySettingsControlFlags
{
335 SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS
= 0x01,
338 enum Http2SettingsControlFlags
{
339 SETTINGS_FLAG_ACK
= 0x01,
342 // Flags for settings within a SETTINGS frame.
343 enum SpdySettingsFlags
{
344 SETTINGS_FLAG_NONE
= 0x00,
345 SETTINGS_FLAG_PLEASE_PERSIST
= 0x01,
346 SETTINGS_FLAG_PERSISTED
= 0x02,
349 // List of known settings. Avoid changing these enum values, as persisted
350 // settings are keyed on them, and they are also exposed in net-internals.
351 enum SpdySettingsIds
{
352 SETTINGS_UPLOAD_BANDWIDTH
= 0x1,
353 SETTINGS_DOWNLOAD_BANDWIDTH
= 0x2,
354 // Network round trip time in milliseconds.
355 SETTINGS_ROUND_TRIP_TIME
= 0x3,
356 // The maximum number of simultaneous live streams in each direction.
357 SETTINGS_MAX_CONCURRENT_STREAMS
= 0x4,
358 // TCP congestion window in packets.
359 SETTINGS_CURRENT_CWND
= 0x5,
360 // Downstream byte retransmission rate in percentage.
361 SETTINGS_DOWNLOAD_RETRANS_RATE
= 0x6,
362 // Initial window size in bytes
363 SETTINGS_INITIAL_WINDOW_SIZE
= 0x7,
364 // HPACK header table maximum size.
365 SETTINGS_HEADER_TABLE_SIZE
= 0x8,
366 // Whether or not server push (PUSH_PROMISE) is enabled.
367 SETTINGS_ENABLE_PUSH
= 0x9,
368 // The size of the largest frame payload that a receiver is willing to accept.
369 SETTINGS_MAX_FRAME_SIZE
= 0xa,
370 // The maximum size of header list that the sender is prepared to accept.
371 SETTINGS_MAX_HEADER_LIST_SIZE
= 0xb,
374 // Status codes for RST_STREAM frames.
375 enum SpdyRstStreamStatus
{
376 RST_STREAM_INVALID
= 0,
377 RST_STREAM_PROTOCOL_ERROR
= 1,
378 RST_STREAM_INVALID_STREAM
= 2,
379 RST_STREAM_STREAM_CLOSED
= 2, // Equivalent to INVALID_STREAM
380 RST_STREAM_REFUSED_STREAM
= 3,
381 RST_STREAM_UNSUPPORTED_VERSION
= 4,
382 RST_STREAM_CANCEL
= 5,
383 RST_STREAM_INTERNAL_ERROR
= 6,
384 RST_STREAM_FLOW_CONTROL_ERROR
= 7,
385 RST_STREAM_STREAM_IN_USE
= 8,
386 RST_STREAM_STREAM_ALREADY_CLOSED
= 9,
387 RST_STREAM_INVALID_CREDENTIALS
= 10,
388 // FRAME_TOO_LARGE (defined by SPDY versions 3.1 and below), and
389 // FRAME_SIZE_ERROR (defined by HTTP/2) are mapped to the same internal
391 RST_STREAM_FRAME_TOO_LARGE
= 11,
392 RST_STREAM_FRAME_SIZE_ERROR
= 11,
393 RST_STREAM_SETTINGS_TIMEOUT
= 12,
394 RST_STREAM_CONNECT_ERROR
= 13,
395 RST_STREAM_ENHANCE_YOUR_CALM
= 14,
396 RST_STREAM_INADEQUATE_SECURITY
= 15,
397 RST_STREAM_HTTP_1_1_REQUIRED
= 16,
398 RST_STREAM_NUM_STATUS_CODES
= 17
401 // Status codes for GOAWAY frames.
402 enum SpdyGoAwayStatus
{
404 GOAWAY_NO_ERROR
= GOAWAY_OK
,
405 GOAWAY_PROTOCOL_ERROR
= 1,
406 GOAWAY_INTERNAL_ERROR
= 2,
407 GOAWAY_FLOW_CONTROL_ERROR
= 3,
408 GOAWAY_SETTINGS_TIMEOUT
= 4,
409 GOAWAY_STREAM_CLOSED
= 5,
410 GOAWAY_FRAME_SIZE_ERROR
= 6,
411 GOAWAY_REFUSED_STREAM
= 7,
413 GOAWAY_COMPRESSION_ERROR
= 9,
414 GOAWAY_CONNECT_ERROR
= 10,
415 GOAWAY_ENHANCE_YOUR_CALM
= 11,
416 GOAWAY_INADEQUATE_SECURITY
= 12,
417 GOAWAY_HTTP_1_1_REQUIRED
= 13
420 // A SPDY priority is a number between 0 and 7 (inclusive).
421 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a
422 // number between 0 and 3.
423 typedef uint8 SpdyPriority
;
425 typedef std::map
<std::string
, std::string
> SpdyNameValueBlock
;
427 typedef uint64 SpdyPingId
;
429 typedef std::string SpdyProtocolId
;
431 enum class SpdyHeaderValidatorType
{ REQUEST
, RESPONSE
};
433 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any,
434 // but is good to do anyway.
435 class NET_EXPORT_PRIVATE SpdyConstants
{
437 // Returns true if a given on-the-wire enumeration of a frame type is valid
438 // for a given protocol version, false otherwise.
439 static bool IsValidFrameType(SpdyMajorVersion version
, int frame_type_field
);
441 // Parses a frame type from an on-the-wire enumeration of a given protocol
443 // Behavior is undefined for invalid frame type fields; consumers should first
444 // use IsValidFrameType() to verify validity of frame type fields.
445 static SpdyFrameType
ParseFrameType(SpdyMajorVersion version
,
446 int frame_type_field
);
448 // Serializes a given frame type to the on-the-wire enumeration value for the
449 // given protocol version.
450 // Returns -1 on failure (I.E. Invalid frame type for the given version).
451 static int SerializeFrameType(SpdyMajorVersion version
,
452 SpdyFrameType frame_type
);
454 // Returns the frame type for non-control (i.e. data) frames
455 // in the given SPDY version.
456 static int DataFrameType(SpdyMajorVersion version
);
458 // Returns true if a given on-the-wire enumeration of a setting id is valid
459 // for a given protocol version, false otherwise.
460 static bool IsValidSettingId(SpdyMajorVersion version
, int setting_id_field
);
462 // Parses a setting id from an on-the-wire enumeration of a given protocol
464 // Behavior is undefined for invalid setting id fields; consumers should first
465 // use IsValidSettingId() to verify validity of setting id fields.
466 static SpdySettingsIds
ParseSettingId(SpdyMajorVersion version
,
467 int setting_id_field
);
469 // Serializes a given setting id to the on-the-wire enumeration value for the
470 // given protocol version.
471 // Returns -1 on failure (I.E. Invalid setting id for the given version).
472 static int SerializeSettingId(SpdyMajorVersion version
, SpdySettingsIds id
);
474 // Returns true if a given on-the-wire enumeration of a RST_STREAM status code
475 // is valid for a given protocol version, false otherwise.
476 static bool IsValidRstStreamStatus(SpdyMajorVersion version
,
477 int rst_stream_status_field
);
479 // Parses a RST_STREAM status code from an on-the-wire enumeration of a given
481 // Behavior is undefined for invalid RST_STREAM status code fields; consumers
482 // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM
483 // status code fields..
484 static SpdyRstStreamStatus
ParseRstStreamStatus(SpdyMajorVersion version
,
485 int rst_stream_status_field
);
487 // Serializes a given RST_STREAM status code to the on-the-wire enumeration
488 // value for the given protocol version.
489 // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given
491 static int SerializeRstStreamStatus(SpdyMajorVersion version
,
492 SpdyRstStreamStatus rst_stream_status
);
494 // Returns true if a given on-the-wire enumeration of a GOAWAY status code is
495 // valid for the given protocol version, false otherwise.
496 static bool IsValidGoAwayStatus(SpdyMajorVersion version
,
497 int goaway_status_field
);
499 // Parses a GOAWAY status from an on-the-wire enumeration of a given protocol
501 // Behavior is undefined for invalid GOAWAY status fields; consumers should
502 // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields.
503 static SpdyGoAwayStatus
ParseGoAwayStatus(SpdyMajorVersion version
,
504 int goaway_status_field
);
506 // Serializes a given GOAWAY status to the on-the-wire enumeration value for
507 // the given protocol version.
508 // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version).
509 static int SerializeGoAwayStatus(SpdyMajorVersion version
,
510 SpdyGoAwayStatus status
);
512 // Size, in bytes, of the data frame header. Future versions of SPDY
513 // will likely vary this, so we allow for the flexibility of a function call
514 // for this value as opposed to a constant.
515 static size_t GetDataFrameMinimumSize(SpdyMajorVersion version
);
517 // Size, in bytes, of the control frame header.
518 static size_t GetControlFrameHeaderSize(SpdyMajorVersion version
);
520 static size_t GetPrefixLength(SpdyFrameType type
, SpdyMajorVersion version
);
522 static size_t GetFrameMaximumSize(SpdyMajorVersion version
);
524 // Returns the size of a header block size field. Valid only for SPDY
526 static size_t GetSizeOfSizeField(SpdyMajorVersion version
);
528 // Returns the size (in bytes) of a wire setting ID and value.
529 static size_t GetSettingSize(SpdyMajorVersion version
);
531 // Initial window size for a stream in bytes.
532 static int32
GetInitialStreamWindowSize(SpdyMajorVersion version
);
534 // Initial window size for a session in bytes.
535 static int32
GetInitialSessionWindowSize(SpdyMajorVersion version
);
537 static SpdyMajorVersion
ParseMajorVersion(int version_number
);
539 static int SerializeMajorVersion(SpdyMajorVersion version
);
541 static std::string
GetVersionString(SpdyMajorVersion version
);
545 typedef SpdyFrame SpdySerializedFrame
;
547 class SpdyFrameVisitor
;
549 // Intermediate representation for SPDY frames.
550 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is
552 class NET_EXPORT_PRIVATE SpdyFrameIR
{
554 virtual ~SpdyFrameIR() {}
556 virtual void Visit(SpdyFrameVisitor
* visitor
) const = 0;
562 DISALLOW_COPY_AND_ASSIGN(SpdyFrameIR
);
565 // Abstract class intended to be inherited by IRs that have a stream associated
567 class NET_EXPORT_PRIVATE SpdyFrameWithStreamIdIR
: public SpdyFrameIR
{
569 ~SpdyFrameWithStreamIdIR() override
{}
570 SpdyStreamId
stream_id() const { return stream_id_
; }
571 void set_stream_id(SpdyStreamId stream_id
) {
572 DCHECK_EQ(0u, stream_id
& ~kStreamIdMask
);
573 stream_id_
= stream_id
;
577 explicit SpdyFrameWithStreamIdIR(SpdyStreamId stream_id
) {
578 set_stream_id(stream_id
);
582 SpdyStreamId stream_id_
;
584 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithStreamIdIR
);
587 // Abstract class intended to be inherited by IRs that have the option of a FIN
588 // flag. Implies SpdyFrameWithStreamIdIR.
589 class NET_EXPORT_PRIVATE SpdyFrameWithFinIR
: public SpdyFrameWithStreamIdIR
{
591 ~SpdyFrameWithFinIR() override
{}
592 bool fin() const { return fin_
; }
593 void set_fin(bool fin
) { fin_
= fin
; }
596 explicit SpdyFrameWithFinIR(SpdyStreamId stream_id
)
597 : SpdyFrameWithStreamIdIR(stream_id
),
603 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithFinIR
);
606 // Abstract class intended to be inherited by IRs that contain a name-value
607 // block. Implies SpdyFrameWithFinIR.
608 class NET_EXPORT_PRIVATE SpdyFrameWithNameValueBlockIR
609 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR
) {
611 const SpdyNameValueBlock
& name_value_block() const {
612 return name_value_block_
;
614 void set_name_value_block(const SpdyNameValueBlock
& name_value_block
) {
616 name_value_block_
= name_value_block
;
618 void SetHeader(base::StringPiece name
, base::StringPiece value
) {
619 name_value_block_
[name
.as_string()] = value
.as_string();
621 SpdyNameValueBlock
* mutable_name_value_block() {
622 return &name_value_block_
;
626 explicit SpdyFrameWithNameValueBlockIR(SpdyStreamId stream_id
);
627 ~SpdyFrameWithNameValueBlockIR() override
;
630 SpdyNameValueBlock name_value_block_
;
632 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithNameValueBlockIR
);
635 class NET_EXPORT_PRIVATE SpdyDataIR
636 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR
) {
638 // Performs deep copy on data.
639 SpdyDataIR(SpdyStreamId stream_id
, base::StringPiece data
);
641 // Use in conjunction with SetDataShallow() for shallow-copy on data.
642 explicit SpdyDataIR(SpdyStreamId stream_id
);
644 ~SpdyDataIR() override
;
646 base::StringPiece
data() const { return data_
; }
648 bool padded() const { return padded_
; }
650 int padding_payload_len() const { return padding_payload_len_
; }
652 void set_padding_len(int padding_len
) {
653 DCHECK_GT(padding_len
, 0);
654 DCHECK_LE(padding_len
, kPaddingSizePerFrame
);
656 // The pad field takes one octet on the wire.
657 padding_payload_len_
= padding_len
- 1;
660 // Deep-copy of data (keep private copy).
661 void SetDataDeep(base::StringPiece data
) {
662 data_store_
.reset(new std::string(data
.data(), data
.length()));
663 data_
= *(data_store_
.get());
666 // Shallow-copy of data (do not keep private copy).
667 void SetDataShallow(base::StringPiece data
) {
672 void Visit(SpdyFrameVisitor
* visitor
) const override
;
675 // Used to store data that this SpdyDataIR should own.
676 scoped_ptr
<std::string
> data_store_
;
677 base::StringPiece data_
;
680 // padding_payload_len_ = desired padding length - len(padding length field).
681 int padding_payload_len_
;
683 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR
);
686 class NET_EXPORT_PRIVATE SpdySynStreamIR
687 : public SpdyFrameWithNameValueBlockIR
{
689 explicit SpdySynStreamIR(SpdyStreamId stream_id
)
690 : SpdyFrameWithNameValueBlockIR(stream_id
),
691 associated_to_stream_id_(0),
693 unidirectional_(false) {}
694 SpdyStreamId
associated_to_stream_id() const {
695 return associated_to_stream_id_
;
697 void set_associated_to_stream_id(SpdyStreamId stream_id
) {
698 associated_to_stream_id_
= stream_id
;
700 SpdyPriority
priority() const { return priority_
; }
701 void set_priority(SpdyPriority priority
) { priority_
= priority
; }
702 bool unidirectional() const { return unidirectional_
; }
703 void set_unidirectional(bool unidirectional
) {
704 unidirectional_
= unidirectional
;
707 void Visit(SpdyFrameVisitor
* visitor
) const override
;
710 SpdyStreamId associated_to_stream_id_
;
711 SpdyPriority priority_
;
712 bool unidirectional_
;
714 DISALLOW_COPY_AND_ASSIGN(SpdySynStreamIR
);
717 class NET_EXPORT_PRIVATE SpdySynReplyIR
: public SpdyFrameWithNameValueBlockIR
{
719 explicit SpdySynReplyIR(SpdyStreamId stream_id
)
720 : SpdyFrameWithNameValueBlockIR(stream_id
) {}
722 void Visit(SpdyFrameVisitor
* visitor
) const override
;
725 DISALLOW_COPY_AND_ASSIGN(SpdySynReplyIR
);
728 class NET_EXPORT_PRIVATE SpdyRstStreamIR
: public SpdyFrameWithStreamIdIR
{
730 SpdyRstStreamIR(SpdyStreamId stream_id
, SpdyRstStreamStatus status
,
731 base::StringPiece description
);
733 ~SpdyRstStreamIR() override
;
735 SpdyRstStreamStatus
status() const {
738 void set_status(SpdyRstStreamStatus status
) {
742 base::StringPiece
description() const { return description_
; }
744 void Visit(SpdyFrameVisitor
* visitor
) const override
;
747 SpdyRstStreamStatus status_
;
748 base::StringPiece description_
;
750 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR
);
753 class NET_EXPORT_PRIVATE SpdySettingsIR
: public SpdyFrameIR
{
755 // Associates flags with a value.
757 Value() : persist_value(false),
764 typedef std::map
<SpdySettingsIds
, Value
> ValueMap
;
768 ~SpdySettingsIR() override
;
770 // Overwrites as appropriate.
771 const ValueMap
& values() const { return values_
; }
772 void AddSetting(SpdySettingsIds id
,
776 values_
[id
].persist_value
= persist_value
;
777 values_
[id
].persisted
= persisted
;
778 values_
[id
].value
= value
;
781 bool clear_settings() const { return clear_settings_
; }
782 bool is_ack() const { return is_ack_
; }
783 void set_is_ack(bool is_ack
) {
787 void Visit(SpdyFrameVisitor
* visitor
) const override
;
791 bool clear_settings_
;
794 DISALLOW_COPY_AND_ASSIGN(SpdySettingsIR
);
797 class NET_EXPORT_PRIVATE SpdyPingIR
: public SpdyFrameIR
{
799 explicit SpdyPingIR(SpdyPingId id
) : id_(id
), is_ack_(false) {}
800 SpdyPingId
id() const { return id_
; }
802 // ACK logic is valid only for SPDY versions 4 and above.
803 bool is_ack() const { return is_ack_
; }
804 void set_is_ack(bool is_ack
) { is_ack_
= is_ack
; }
806 void Visit(SpdyFrameVisitor
* visitor
) const override
;
812 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR
);
815 class NET_EXPORT_PRIVATE SpdyGoAwayIR
: public SpdyFrameIR
{
817 SpdyGoAwayIR(SpdyStreamId last_good_stream_id
,
818 SpdyGoAwayStatus status
,
819 base::StringPiece description
);
820 ~SpdyGoAwayIR() override
;
821 SpdyStreamId
last_good_stream_id() const { return last_good_stream_id_
; }
822 void set_last_good_stream_id(SpdyStreamId last_good_stream_id
) {
823 DCHECK_LE(0u, last_good_stream_id
);
824 DCHECK_EQ(0u, last_good_stream_id
& ~kStreamIdMask
);
825 last_good_stream_id_
= last_good_stream_id
;
827 SpdyGoAwayStatus
status() const { return status_
; }
828 void set_status(SpdyGoAwayStatus status
) {
829 // TODO(hkhalil): Check valid ranges of status?
833 const base::StringPiece
& description() const;
835 void Visit(SpdyFrameVisitor
* visitor
) const override
;
838 SpdyStreamId last_good_stream_id_
;
839 SpdyGoAwayStatus status_
;
840 const base::StringPiece description_
;
842 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR
);
845 class NET_EXPORT_PRIVATE SpdyHeadersIR
: public SpdyFrameWithNameValueBlockIR
{
847 explicit SpdyHeadersIR(SpdyStreamId stream_id
)
848 : SpdyFrameWithNameValueBlockIR(stream_id
),
849 has_priority_(false),
852 padding_payload_len_(0) {}
854 void Visit(SpdyFrameVisitor
* visitor
) const override
;
856 bool has_priority() const { return has_priority_
; }
857 void set_has_priority(bool has_priority
) { has_priority_
= has_priority
; }
858 uint32
priority() const { return priority_
; }
859 void set_priority(SpdyPriority priority
) { priority_
= priority
; }
861 bool padded() const { return padded_
; }
862 int padding_payload_len() const { return padding_payload_len_
; }
863 void set_padding_len(int padding_len
) {
864 DCHECK_GT(padding_len
, 0);
865 DCHECK_LE(padding_len
, kPaddingSizePerFrame
);
867 // The pad field takes one octet on the wire.
868 padding_payload_len_
= padding_len
- 1;
877 int padding_payload_len_
;
879 DISALLOW_COPY_AND_ASSIGN(SpdyHeadersIR
);
882 class NET_EXPORT_PRIVATE SpdyWindowUpdateIR
: public SpdyFrameWithStreamIdIR
{
884 SpdyWindowUpdateIR(SpdyStreamId stream_id
, int32 delta
)
885 : SpdyFrameWithStreamIdIR(stream_id
) {
888 int32
delta() const { return delta_
; }
889 void set_delta(int32 delta
) {
891 DCHECK_LE(delta
, kSpdyMaximumWindowSize
);
895 void Visit(SpdyFrameVisitor
* visitor
) const override
;
900 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateIR
);
903 class NET_EXPORT_PRIVATE SpdyBlockedIR
904 : public NON_EXPORTED_BASE(SpdyFrameWithStreamIdIR
) {
906 explicit SpdyBlockedIR(SpdyStreamId stream_id
)
907 : SpdyFrameWithStreamIdIR(stream_id
) {}
909 void Visit(SpdyFrameVisitor
* visitor
) const override
;
912 DISALLOW_COPY_AND_ASSIGN(SpdyBlockedIR
);
915 class NET_EXPORT_PRIVATE SpdyPushPromiseIR
916 : public SpdyFrameWithNameValueBlockIR
{
918 SpdyPushPromiseIR(SpdyStreamId stream_id
, SpdyStreamId promised_stream_id
)
919 : SpdyFrameWithNameValueBlockIR(stream_id
),
920 promised_stream_id_(promised_stream_id
),
922 padding_payload_len_(0) {}
923 SpdyStreamId
promised_stream_id() const { return promised_stream_id_
; }
925 void Visit(SpdyFrameVisitor
* visitor
) const override
;
927 bool padded() const { return padded_
; }
928 int padding_payload_len() const { return padding_payload_len_
; }
929 void set_padding_len(int padding_len
) {
930 DCHECK_GT(padding_len
, 0);
931 DCHECK_LE(padding_len
, kPaddingSizePerFrame
);
933 // The pad field takes one octet on the wire.
934 padding_payload_len_
= padding_len
- 1;
938 SpdyStreamId promised_stream_id_
;
941 int padding_payload_len_
;
943 DISALLOW_COPY_AND_ASSIGN(SpdyPushPromiseIR
);
946 // TODO(jgraettinger): This representation needs review. SpdyContinuationIR
947 // needs to frame a portion of a single, arbitrarily-broken encoded buffer.
948 class NET_EXPORT_PRIVATE SpdyContinuationIR
949 : public SpdyFrameWithNameValueBlockIR
{
951 explicit SpdyContinuationIR(SpdyStreamId stream_id
)
952 : SpdyFrameWithNameValueBlockIR(stream_id
),
953 end_headers_(false) {}
955 void Visit(SpdyFrameVisitor
* visitor
) const override
;
957 bool end_headers() const { return end_headers_
; }
958 void set_end_headers(bool end_headers
) {end_headers_
= end_headers
;}
962 DISALLOW_COPY_AND_ASSIGN(SpdyContinuationIR
);
965 // TODO(bnc): Add probability.
966 // TODO(bnc): Separate (protocol, port, host, max_age, probability) tuple into
967 // struct, have a vector of that struct. A single HTTP/1.1 header field or
968 // HTTP/2 or QUIC frame can define multiple such tuples.
969 class NET_EXPORT_PRIVATE SpdyAltSvcIR
: public SpdyFrameWithStreamIdIR
{
971 explicit SpdyAltSvcIR(SpdyStreamId stream_id
);
973 std::string
origin() const { return origin_
; }
974 const SpdyAltSvcWireFormat::AlternativeService
& altsvc() const {
977 SpdyProtocolId
protocol_id() const { return altsvc_
.protocol_id
; }
978 std::string
host() const { return altsvc_
.host
; }
979 uint16
port() const { return altsvc_
.port
; }
980 uint32
max_age() const { return altsvc_
.max_age
; }
981 double p() const { return altsvc_
.p
; }
983 void set_origin(std::string origin
) { origin_
= origin
; }
984 void set_protocol_id(SpdyProtocolId protocol_id
) {
985 altsvc_
.protocol_id
= protocol_id
;
987 void set_host(std::string host
) { altsvc_
.host
= host
; }
988 void set_port(uint16 port
) { altsvc_
.port
= port
; }
989 void set_max_age(uint32 max_age
) { altsvc_
.max_age
= max_age
; }
990 void set_p(double p
) { altsvc_
.p
= p
; }
992 void Visit(SpdyFrameVisitor
* visitor
) const override
;
996 SpdyAltSvcWireFormat::AlternativeService altsvc_
;
997 DISALLOW_COPY_AND_ASSIGN(SpdyAltSvcIR
);
1000 class NET_EXPORT_PRIVATE SpdyPriorityIR
: public SpdyFrameWithStreamIdIR
{
1002 explicit SpdyPriorityIR(SpdyStreamId stream_id
)
1003 : SpdyFrameWithStreamIdIR(stream_id
),
1004 parent_stream_id_(0),
1006 exclusive_(false) {}
1007 SpdyPriorityIR(SpdyStreamId stream_id
,
1008 SpdyStreamId parent_stream_id
,
1011 : SpdyFrameWithStreamIdIR(stream_id
),
1012 parent_stream_id_(parent_stream_id
),
1014 exclusive_(exclusive
) {}
1015 SpdyStreamId
parent_stream_id() const { return parent_stream_id_
; }
1016 void set_parent_stream_id(SpdyStreamId id
) { parent_stream_id_
= id
; }
1017 uint8
weight() const { return weight_
; }
1018 void set_weight(uint8 weight
) { weight_
= weight
; }
1019 bool exclusive() const { return exclusive_
; }
1020 void set_exclusive(bool exclusive
) { exclusive_
= exclusive
; }
1022 void Visit(SpdyFrameVisitor
* visitor
) const override
;
1025 SpdyStreamId parent_stream_id_
;
1028 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR
);
1031 // -------------------------------------------------------------------------
1032 // Wrapper classes for various SPDY frames.
1034 // All Spdy Frame types derive from this SpdyFrame class.
1037 // Create a SpdyFrame using a pre-created buffer.
1038 // If |owns_buffer| is true, this class takes ownership of the buffer
1039 // and will delete it on cleanup. The buffer must have been created using
1041 // If |owns_buffer| is false, the caller retains ownership of the buffer and
1042 // is responsible for making sure the buffer outlives this frame. In other
1043 // words, this class does NOT create a copy of the buffer.
1044 SpdyFrame(char* data
, size_t size
, bool owns_buffer
)
1047 owns_buffer_(owns_buffer
) {
1058 // Provides access to the frame bytes, which is a buffer containing
1059 // the frame packed as expected for sending over the wire.
1060 char* data() const { return frame_
; }
1062 // Returns the actual size of the underlying buffer.
1063 size_t size() const { return size_
; }
1071 DISALLOW_COPY_AND_ASSIGN(SpdyFrame
);
1074 // This interface is for classes that want to process SpdyFrameIRs without
1075 // having to know what type they are. An instance of this interface can be
1076 // passed to a SpdyFrameIR's Visit method, and the appropriate type-specific
1077 // method of this class will be called.
1078 class SpdyFrameVisitor
{
1080 virtual void VisitSynStream(const SpdySynStreamIR
& syn_stream
) = 0;
1081 virtual void VisitSynReply(const SpdySynReplyIR
& syn_reply
) = 0;
1082 virtual void VisitRstStream(const SpdyRstStreamIR
& rst_stream
) = 0;
1083 virtual void VisitSettings(const SpdySettingsIR
& settings
) = 0;
1084 virtual void VisitPing(const SpdyPingIR
& ping
) = 0;
1085 virtual void VisitGoAway(const SpdyGoAwayIR
& goaway
) = 0;
1086 virtual void VisitHeaders(const SpdyHeadersIR
& headers
) = 0;
1087 virtual void VisitWindowUpdate(const SpdyWindowUpdateIR
& window_update
) = 0;
1088 virtual void VisitBlocked(const SpdyBlockedIR
& blocked
) = 0;
1089 virtual void VisitPushPromise(const SpdyPushPromiseIR
& push_promise
) = 0;
1090 virtual void VisitContinuation(const SpdyContinuationIR
& continuation
) = 0;
1091 virtual void VisitAltSvc(const SpdyAltSvcIR
& altsvc
) = 0;
1092 virtual void VisitPriority(const SpdyPriorityIR
& priority
) = 0;
1093 virtual void VisitData(const SpdyDataIR
& data
) = 0;
1096 SpdyFrameVisitor() {}
1097 virtual ~SpdyFrameVisitor() {}
1100 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor
);
1105 #endif // NET_SPDY_SPDY_PROTOCOL_H_