Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / spdy / spdy_protocol.h
blob2e4fde870997ba5f8cb1f2fc73e3f7f6347a4087
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>
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"
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 HTTP2 = 4,
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
46 // flow control).
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;
61 // SPDY 2 dictionary.
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"
76 ".1statusversionurl";
77 const int kV2DictionarySize = arraysize(kV2Dictionary);
79 // SPDY 3 dictionary.
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.
279 enum SpdyFrameType {
280 DATA,
281 SYN_STREAM,
282 SYN_REPLY,
283 RST_STREAM,
284 SETTINGS,
285 PING,
286 GOAWAY,
287 HEADERS,
288 WINDOW_UPDATE,
289 CREDENTIAL = 10, // No longer valid. Kept for identifiability.
290 PUSH_PROMISE,
291 CONTINUATION,
292 PRIORITY,
293 // BLOCKED and ALTSVC are recognized extensions.
294 BLOCKED,
295 ALTSVC,
298 // Flags on data packets.
299 enum SpdyDataFlags {
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,
314 enum SpdyPingFlags {
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
388 // reset status.
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 {
401 GOAWAY_OK = 0,
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,
410 GOAWAY_CANCEL = 8,
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 // A datastructure for holding a set of headers from a HEADERS, PUSH_PROMISE,
424 // SYN_STREAM, or SYN_REPLY frame.
425 typedef std::map<std::string, std::string> SpdyHeaderBlock;
427 typedef uint64 SpdyPingId;
429 typedef std::string SpdyProtocolId;
431 enum class SpdyHeaderValidatorType {
432 REQUEST,
433 RESPONSE_HEADER,
434 RESPONSE_TRAILER
437 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any,
438 // but is good to do anyway.
439 class NET_EXPORT_PRIVATE SpdyConstants {
440 public:
441 // Returns true if a given on-the-wire enumeration of a frame type is valid
442 // for a given protocol version, false otherwise.
443 static bool IsValidFrameType(SpdyMajorVersion version, int frame_type_field);
445 // Parses a frame type from an on-the-wire enumeration of a given protocol
446 // version.
447 // Behavior is undefined for invalid frame type fields; consumers should first
448 // use IsValidFrameType() to verify validity of frame type fields.
449 static SpdyFrameType ParseFrameType(SpdyMajorVersion version,
450 int frame_type_field);
452 // Serializes a given frame type to the on-the-wire enumeration value for the
453 // given protocol version.
454 // Returns -1 on failure (I.E. Invalid frame type for the given version).
455 static int SerializeFrameType(SpdyMajorVersion version,
456 SpdyFrameType frame_type);
458 // Returns the frame type for non-control (i.e. data) frames
459 // in the given SPDY version.
460 static int DataFrameType(SpdyMajorVersion version);
462 // Returns true if a given on-the-wire enumeration of a setting id is valid
463 // for a given protocol version, false otherwise.
464 static bool IsValidSettingId(SpdyMajorVersion version, int setting_id_field);
466 // Parses a setting id from an on-the-wire enumeration of a given protocol
467 // version.
468 // Behavior is undefined for invalid setting id fields; consumers should first
469 // use IsValidSettingId() to verify validity of setting id fields.
470 static SpdySettingsIds ParseSettingId(SpdyMajorVersion version,
471 int setting_id_field);
473 // Serializes a given setting id to the on-the-wire enumeration value for the
474 // given protocol version.
475 // Returns -1 on failure (I.E. Invalid setting id for the given version).
476 static int SerializeSettingId(SpdyMajorVersion version, SpdySettingsIds id);
478 // Returns true if a given on-the-wire enumeration of a RST_STREAM status code
479 // is valid for a given protocol version, false otherwise.
480 static bool IsValidRstStreamStatus(SpdyMajorVersion version,
481 int rst_stream_status_field);
483 // Parses a RST_STREAM status code from an on-the-wire enumeration of a given
484 // protocol version.
485 // Behavior is undefined for invalid RST_STREAM status code fields; consumers
486 // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM
487 // status code fields..
488 static SpdyRstStreamStatus ParseRstStreamStatus(SpdyMajorVersion version,
489 int rst_stream_status_field);
491 // Serializes a given RST_STREAM status code to the on-the-wire enumeration
492 // value for the given protocol version.
493 // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given
494 // version).
495 static int SerializeRstStreamStatus(SpdyMajorVersion version,
496 SpdyRstStreamStatus rst_stream_status);
498 // Returns true if a given on-the-wire enumeration of a GOAWAY status code is
499 // valid for the given protocol version, false otherwise.
500 static bool IsValidGoAwayStatus(SpdyMajorVersion version,
501 int goaway_status_field);
503 // Parses a GOAWAY status from an on-the-wire enumeration of a given protocol
504 // version.
505 // Behavior is undefined for invalid GOAWAY status fields; consumers should
506 // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields.
507 static SpdyGoAwayStatus ParseGoAwayStatus(SpdyMajorVersion version,
508 int goaway_status_field);
510 // Serializes a given GOAWAY status to the on-the-wire enumeration value for
511 // the given protocol version.
512 // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version).
513 static int SerializeGoAwayStatus(SpdyMajorVersion version,
514 SpdyGoAwayStatus status);
516 // Size, in bytes, of the data frame header. Future versions of SPDY
517 // will likely vary this, so we allow for the flexibility of a function call
518 // for this value as opposed to a constant.
519 static size_t GetDataFrameMinimumSize(SpdyMajorVersion version);
521 // Size, in bytes, of the control frame header.
522 static size_t GetControlFrameHeaderSize(SpdyMajorVersion version);
524 static size_t GetPrefixLength(SpdyFrameType type, SpdyMajorVersion version);
526 static size_t GetFrameMaximumSize(SpdyMajorVersion version);
528 // Returns the size of a header block size field. Valid only for SPDY
529 // versions <= 3.
530 static size_t GetSizeOfSizeField(SpdyMajorVersion version);
532 // Returns the size (in bytes) of a wire setting ID and value.
533 static size_t GetSettingSize(SpdyMajorVersion version);
535 // Initial window size for a stream in bytes.
536 static int32 GetInitialStreamWindowSize(SpdyMajorVersion version);
538 // Initial window size for a session in bytes.
539 static int32 GetInitialSessionWindowSize(SpdyMajorVersion version);
541 static SpdyMajorVersion ParseMajorVersion(int version_number);
543 static int SerializeMajorVersion(SpdyMajorVersion version);
545 static std::string GetVersionString(SpdyMajorVersion version);
548 class SpdyFrame;
549 typedef SpdyFrame SpdySerializedFrame;
551 class SpdyFrameVisitor;
553 // Intermediate representation for SPDY frames.
554 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is
555 // gone.
556 class NET_EXPORT_PRIVATE SpdyFrameIR {
557 public:
558 virtual ~SpdyFrameIR() {}
560 virtual void Visit(SpdyFrameVisitor* visitor) const = 0;
562 protected:
563 SpdyFrameIR() {}
565 private:
566 DISALLOW_COPY_AND_ASSIGN(SpdyFrameIR);
569 // Abstract class intended to be inherited by IRs that have a stream associated
570 // to them.
571 class NET_EXPORT_PRIVATE SpdyFrameWithStreamIdIR : public SpdyFrameIR {
572 public:
573 ~SpdyFrameWithStreamIdIR() override {}
574 SpdyStreamId stream_id() const { return stream_id_; }
575 void set_stream_id(SpdyStreamId stream_id) {
576 DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
577 stream_id_ = stream_id;
580 protected:
581 explicit SpdyFrameWithStreamIdIR(SpdyStreamId stream_id) {
582 set_stream_id(stream_id);
585 private:
586 SpdyStreamId stream_id_;
588 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithStreamIdIR);
591 // Abstract class intended to be inherited by IRs that have the option of a FIN
592 // flag. Implies SpdyFrameWithStreamIdIR.
593 class NET_EXPORT_PRIVATE SpdyFrameWithFinIR : public SpdyFrameWithStreamIdIR {
594 public:
595 ~SpdyFrameWithFinIR() override {}
596 bool fin() const { return fin_; }
597 void set_fin(bool fin) { fin_ = fin; }
599 protected:
600 explicit SpdyFrameWithFinIR(SpdyStreamId stream_id)
601 : SpdyFrameWithStreamIdIR(stream_id),
602 fin_(false) {}
604 private:
605 bool fin_;
607 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithFinIR);
610 // Abstract class intended to be inherited by IRs that contain a header
611 // block. Implies SpdyFrameWithFinIR.
612 class NET_EXPORT_PRIVATE SpdyFrameWithHeaderBlockIR
613 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) {
614 public:
615 const SpdyHeaderBlock& header_block() const { return header_block_; }
616 void set_header_block(const SpdyHeaderBlock& header_block) {
617 // Deep copy.
618 header_block_ = header_block;
620 void SetHeader(base::StringPiece name, base::StringPiece value) {
621 header_block_[name.as_string()] = value.as_string();
623 SpdyHeaderBlock* mutable_header_block() { return &header_block_; }
625 protected:
626 explicit SpdyFrameWithHeaderBlockIR(SpdyStreamId stream_id);
627 ~SpdyFrameWithHeaderBlockIR() override;
629 private:
630 SpdyHeaderBlock header_block_;
632 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithHeaderBlockIR);
635 class NET_EXPORT_PRIVATE SpdyDataIR
636 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) {
637 public:
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);
655 padded_ = true;
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) {
668 data_store_.reset();
669 data_ = data;
672 void Visit(SpdyFrameVisitor* visitor) const override;
674 private:
675 // Used to store data that this SpdyDataIR should own.
676 scoped_ptr<std::string> data_store_;
677 base::StringPiece data_;
679 bool padded_;
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 : public SpdyFrameWithHeaderBlockIR {
687 public:
688 explicit SpdySynStreamIR(SpdyStreamId stream_id)
689 : SpdyFrameWithHeaderBlockIR(stream_id),
690 associated_to_stream_id_(0),
691 priority_(0),
692 unidirectional_(false) {}
693 SpdyStreamId associated_to_stream_id() const {
694 return associated_to_stream_id_;
696 void set_associated_to_stream_id(SpdyStreamId stream_id) {
697 associated_to_stream_id_ = stream_id;
699 SpdyPriority priority() const { return priority_; }
700 void set_priority(SpdyPriority priority) { priority_ = priority; }
701 bool unidirectional() const { return unidirectional_; }
702 void set_unidirectional(bool unidirectional) {
703 unidirectional_ = unidirectional;
706 void Visit(SpdyFrameVisitor* visitor) const override;
708 private:
709 SpdyStreamId associated_to_stream_id_;
710 SpdyPriority priority_;
711 bool unidirectional_;
713 DISALLOW_COPY_AND_ASSIGN(SpdySynStreamIR);
716 class NET_EXPORT_PRIVATE SpdySynReplyIR : public SpdyFrameWithHeaderBlockIR {
717 public:
718 explicit SpdySynReplyIR(SpdyStreamId stream_id)
719 : SpdyFrameWithHeaderBlockIR(stream_id) {}
721 void Visit(SpdyFrameVisitor* visitor) const override;
723 private:
724 DISALLOW_COPY_AND_ASSIGN(SpdySynReplyIR);
727 class NET_EXPORT_PRIVATE SpdyRstStreamIR : public SpdyFrameWithStreamIdIR {
728 public:
729 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyRstStreamStatus status,
730 base::StringPiece description);
732 ~SpdyRstStreamIR() override;
734 SpdyRstStreamStatus status() const {
735 return status_;
737 void set_status(SpdyRstStreamStatus status) {
738 status_ = status;
741 base::StringPiece description() const { return description_; }
743 void Visit(SpdyFrameVisitor* visitor) const override;
745 private:
746 SpdyRstStreamStatus status_;
747 base::StringPiece description_;
749 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR);
752 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR {
753 public:
754 // Associates flags with a value.
755 struct Value {
756 Value() : persist_value(false),
757 persisted(false),
758 value(0) {}
759 bool persist_value;
760 bool persisted;
761 int32 value;
763 typedef std::map<SpdySettingsIds, Value> ValueMap;
765 SpdySettingsIR();
767 ~SpdySettingsIR() override;
769 // Overwrites as appropriate.
770 const ValueMap& values() const { return values_; }
771 void AddSetting(SpdySettingsIds id,
772 bool persist_value,
773 bool persisted,
774 int32 value) {
775 values_[id].persist_value = persist_value;
776 values_[id].persisted = persisted;
777 values_[id].value = value;
780 bool clear_settings() const { return clear_settings_; }
781 bool is_ack() const { return is_ack_; }
782 void set_is_ack(bool is_ack) {
783 is_ack_ = is_ack;
786 void Visit(SpdyFrameVisitor* visitor) const override;
788 private:
789 ValueMap values_;
790 bool clear_settings_;
791 bool is_ack_;
793 DISALLOW_COPY_AND_ASSIGN(SpdySettingsIR);
796 class NET_EXPORT_PRIVATE SpdyPingIR : public SpdyFrameIR {
797 public:
798 explicit SpdyPingIR(SpdyPingId id) : id_(id), is_ack_(false) {}
799 SpdyPingId id() const { return id_; }
801 // ACK logic is valid only for SPDY versions 4 and above.
802 bool is_ack() const { return is_ack_; }
803 void set_is_ack(bool is_ack) { is_ack_ = is_ack; }
805 void Visit(SpdyFrameVisitor* visitor) const override;
807 private:
808 SpdyPingId id_;
809 bool is_ack_;
811 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR);
814 class NET_EXPORT_PRIVATE SpdyGoAwayIR : public SpdyFrameIR {
815 public:
816 SpdyGoAwayIR(SpdyStreamId last_good_stream_id,
817 SpdyGoAwayStatus status,
818 base::StringPiece description);
819 ~SpdyGoAwayIR() override;
820 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; }
821 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) {
822 DCHECK_LE(0u, last_good_stream_id);
823 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask);
824 last_good_stream_id_ = last_good_stream_id;
826 SpdyGoAwayStatus status() const { return status_; }
827 void set_status(SpdyGoAwayStatus status) {
828 // TODO(hkhalil): Check valid ranges of status?
829 status_ = status;
832 const base::StringPiece& description() const;
834 void Visit(SpdyFrameVisitor* visitor) const override;
836 private:
837 SpdyStreamId last_good_stream_id_;
838 SpdyGoAwayStatus status_;
839 const base::StringPiece description_;
841 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR);
844 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR {
845 public:
846 explicit SpdyHeadersIR(SpdyStreamId stream_id)
847 : SpdyFrameWithHeaderBlockIR(stream_id) {}
849 void Visit(SpdyFrameVisitor* visitor) const override;
851 bool has_priority() const { return has_priority_; }
852 void set_has_priority(bool has_priority) { has_priority_ = has_priority; }
853 uint32 priority() const { return priority_; }
854 void set_priority(SpdyPriority priority) { priority_ = priority; }
855 SpdyStreamId parent_stream_id() const { return parent_stream_id_; }
856 void set_parent_stream_id(SpdyStreamId id) { parent_stream_id_ = id; }
857 bool exclusive() const { return exclusive_; }
858 void set_exclusive(bool exclusive) { exclusive_ = exclusive; }
859 bool padded() const { return padded_; }
860 int padding_payload_len() const { return padding_payload_len_; }
861 void set_padding_len(int padding_len) {
862 DCHECK_GT(padding_len, 0);
863 DCHECK_LE(padding_len, kPaddingSizePerFrame);
864 padded_ = true;
865 // The pad field takes one octet on the wire.
866 padding_payload_len_ = padding_len - 1;
869 private:
870 bool has_priority_ = false;
871 // 31-bit priority.
872 uint32 priority_ = 0;
873 SpdyStreamId parent_stream_id_ = 0;
874 bool exclusive_ = false;
875 bool padded_ = false;
876 int padding_payload_len_ = 0;
878 DISALLOW_COPY_AND_ASSIGN(SpdyHeadersIR);
881 class NET_EXPORT_PRIVATE SpdyWindowUpdateIR : public SpdyFrameWithStreamIdIR {
882 public:
883 SpdyWindowUpdateIR(SpdyStreamId stream_id, int32 delta)
884 : SpdyFrameWithStreamIdIR(stream_id) {
885 set_delta(delta);
887 int32 delta() const { return delta_; }
888 void set_delta(int32 delta) {
889 DCHECK_LT(0, delta);
890 DCHECK_LE(delta, kSpdyMaximumWindowSize);
891 delta_ = delta;
894 void Visit(SpdyFrameVisitor* visitor) const override;
896 private:
897 int32 delta_;
899 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateIR);
902 class NET_EXPORT_PRIVATE SpdyBlockedIR
903 : public NON_EXPORTED_BASE(SpdyFrameWithStreamIdIR) {
904 public:
905 explicit SpdyBlockedIR(SpdyStreamId stream_id)
906 : SpdyFrameWithStreamIdIR(stream_id) {}
908 void Visit(SpdyFrameVisitor* visitor) const override;
910 private:
911 DISALLOW_COPY_AND_ASSIGN(SpdyBlockedIR);
914 class NET_EXPORT_PRIVATE SpdyPushPromiseIR : public SpdyFrameWithHeaderBlockIR {
915 public:
916 SpdyPushPromiseIR(SpdyStreamId stream_id, SpdyStreamId promised_stream_id)
917 : SpdyFrameWithHeaderBlockIR(stream_id),
918 promised_stream_id_(promised_stream_id),
919 padded_(false),
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);
930 padded_ = true;
931 // The pad field takes one octet on the wire.
932 padding_payload_len_ = padding_len - 1;
935 private:
936 SpdyStreamId promised_stream_id_;
938 bool padded_;
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 SpdyFrameWithHeaderBlockIR {
948 public:
949 explicit SpdyContinuationIR(SpdyStreamId stream_id)
950 : SpdyFrameWithHeaderBlockIR(stream_id), end_headers_(false) {}
952 void Visit(SpdyFrameVisitor* visitor) const override;
954 bool end_headers() const { return end_headers_; }
955 void set_end_headers(bool end_headers) {end_headers_ = end_headers;}
957 private:
958 bool end_headers_;
959 DISALLOW_COPY_AND_ASSIGN(SpdyContinuationIR);
962 class NET_EXPORT_PRIVATE SpdyAltSvcIR : public SpdyFrameWithStreamIdIR {
963 public:
964 explicit SpdyAltSvcIR(SpdyStreamId stream_id);
965 ~SpdyAltSvcIR() override;
967 std::string origin() const { return origin_; }
968 const SpdyAltSvcWireFormat::AlternativeServiceVector& altsvc_vector() const {
969 return altsvc_vector_;
972 void set_origin(const std::string origin) { origin_ = origin; }
973 void add_altsvc(const SpdyAltSvcWireFormat::AlternativeService& altsvc) {
974 altsvc_vector_.push_back(altsvc);
977 void Visit(SpdyFrameVisitor* visitor) const override;
979 private:
980 std::string origin_;
981 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector_;
982 DISALLOW_COPY_AND_ASSIGN(SpdyAltSvcIR);
985 class NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR {
986 public:
987 explicit SpdyPriorityIR(SpdyStreamId stream_id)
988 : SpdyFrameWithStreamIdIR(stream_id),
989 parent_stream_id_(0),
990 weight_(1),
991 exclusive_(false) {}
992 SpdyPriorityIR(SpdyStreamId stream_id,
993 SpdyStreamId parent_stream_id,
994 uint8 weight,
995 bool exclusive)
996 : SpdyFrameWithStreamIdIR(stream_id),
997 parent_stream_id_(parent_stream_id),
998 weight_(weight),
999 exclusive_(exclusive) {}
1000 SpdyStreamId parent_stream_id() const { return parent_stream_id_; }
1001 void set_parent_stream_id(SpdyStreamId id) { parent_stream_id_ = id; }
1002 uint8 weight() const { return weight_; }
1003 void set_weight(uint8 weight) { weight_ = weight; }
1004 bool exclusive() const { return exclusive_; }
1005 void set_exclusive(bool exclusive) { exclusive_ = exclusive; }
1007 void Visit(SpdyFrameVisitor* visitor) const override;
1009 private:
1010 SpdyStreamId parent_stream_id_;
1011 uint8 weight_;
1012 bool exclusive_;
1013 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR);
1016 // -------------------------------------------------------------------------
1017 // Wrapper classes for various SPDY frames.
1019 // All Spdy Frame types derive from this SpdyFrame class.
1020 class SpdyFrame {
1021 public:
1022 // Create a SpdyFrame using a pre-created buffer.
1023 // If |owns_buffer| is true, this class takes ownership of the buffer
1024 // and will delete it on cleanup. The buffer must have been created using
1025 // new char[].
1026 // If |owns_buffer| is false, the caller retains ownership of the buffer and
1027 // is responsible for making sure the buffer outlives this frame. In other
1028 // words, this class does NOT create a copy of the buffer.
1029 SpdyFrame(char* data, size_t size, bool owns_buffer)
1030 : frame_(data),
1031 size_(size),
1032 owns_buffer_(owns_buffer) {
1033 DCHECK(frame_);
1036 ~SpdyFrame() {
1037 if (owns_buffer_) {
1038 delete [] frame_;
1040 frame_ = NULL;
1043 // Provides access to the frame bytes, which is a buffer containing
1044 // the frame packed as expected for sending over the wire.
1045 char* data() const { return frame_; }
1047 // Returns the actual size of the underlying buffer.
1048 size_t size() const { return size_; }
1050 protected:
1051 char* frame_;
1053 private:
1054 size_t size_;
1055 bool owns_buffer_;
1056 DISALLOW_COPY_AND_ASSIGN(SpdyFrame);
1059 // This interface is for classes that want to process SpdyFrameIRs without
1060 // having to know what type they are. An instance of this interface can be
1061 // passed to a SpdyFrameIR's Visit method, and the appropriate type-specific
1062 // method of this class will be called.
1063 class SpdyFrameVisitor {
1064 public:
1065 virtual void VisitSynStream(const SpdySynStreamIR& syn_stream) = 0;
1066 virtual void VisitSynReply(const SpdySynReplyIR& syn_reply) = 0;
1067 virtual void VisitRstStream(const SpdyRstStreamIR& rst_stream) = 0;
1068 virtual void VisitSettings(const SpdySettingsIR& settings) = 0;
1069 virtual void VisitPing(const SpdyPingIR& ping) = 0;
1070 virtual void VisitGoAway(const SpdyGoAwayIR& goaway) = 0;
1071 virtual void VisitHeaders(const SpdyHeadersIR& headers) = 0;
1072 virtual void VisitWindowUpdate(const SpdyWindowUpdateIR& window_update) = 0;
1073 virtual void VisitBlocked(const SpdyBlockedIR& blocked) = 0;
1074 virtual void VisitPushPromise(const SpdyPushPromiseIR& push_promise) = 0;
1075 virtual void VisitContinuation(const SpdyContinuationIR& continuation) = 0;
1076 virtual void VisitAltSvc(const SpdyAltSvcIR& altsvc) = 0;
1077 virtual void VisitPriority(const SpdyPriorityIR& priority) = 0;
1078 virtual void VisitData(const SpdyDataIR& data) = 0;
1080 protected:
1081 SpdyFrameVisitor() {}
1082 virtual ~SpdyFrameVisitor() {}
1084 private:
1085 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor);
1088 } // namespace net
1090 #endif // NET_SPDY_SPDY_PROTOCOL_H_