Use touch size for selection handle targetting
[chromium-blink-merge.git] / net / spdy / spdy_protocol.h
blobbd6ff0b7bf4542db8410cd36adc63e7ece05f9c6
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 <map>
15 #include <string>
16 #include <vector>
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_bitmasks.h"
27 namespace net {
29 // The major versions of SPDY. Major version differences indicate
30 // framer-layer incompatibility, as opposed to minor version numbers
31 // which indicate application-layer incompatibility. Do not rely on
32 // the mapping from enum value SPDYn to the integer n.
33 enum SpdyMajorVersion {
34 SPDY2 = 2,
35 SPDY_MIN_VERSION = SPDY2,
36 SPDY3 = 3,
37 SPDY4 = 4,
38 SPDY5 = 5,
39 SPDY_MAX_VERSION = SPDY5
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 // Initial window size for a Spdy stream in bytes.
50 const int32 kSpdyStreamInitialWindowSize = 64 * 1024; // 64 KBytes
52 // Initial window size for a Spdy session in bytes.
53 const int32 kSpdySessionInitialWindowSize = 64 * 1024; // 64 KBytes
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 // Types of SPDY frames.
277 enum SpdyFrameType {
278 DATA,
279 SYN_STREAM,
280 SYN_REPLY,
281 RST_STREAM,
282 SETTINGS,
283 PING,
284 GOAWAY,
285 HEADERS,
286 WINDOW_UPDATE,
287 CREDENTIAL = 10, // No longer valid. Kept for identifiability.
288 BLOCKED,
289 PUSH_PROMISE,
290 CONTINUATION,
291 ALTSVC,
292 PRIORITY
295 // Flags on data packets.
296 enum SpdyDataFlags {
297 DATA_FLAG_NONE = 0x00,
298 DATA_FLAG_FIN = 0x01,
299 DATA_FLAG_END_SEGMENT = 0x02,
300 DATA_FLAG_PADDED = 0x08,
301 DATA_FLAG_COMPRESSED = 0x20,
304 // Flags on control packets
305 enum SpdyControlFlags {
306 CONTROL_FLAG_NONE = 0x00,
307 CONTROL_FLAG_FIN = 0x01,
308 CONTROL_FLAG_UNIDIRECTIONAL = 0x02,
311 enum SpdyPingFlags {
312 PING_FLAG_ACK = 0x01,
315 // Used by HEADERS, PUSH_PROMISE, and CONTINUATION.
316 enum SpdyHeadersFlags {
317 HEADERS_FLAG_END_SEGMENT = 0x02,
318 HEADERS_FLAG_END_HEADERS = 0x04,
319 HEADERS_FLAG_PADDED = 0x08,
320 HEADERS_FLAG_PRIORITY = 0x20,
323 enum SpdyPushPromiseFlags {
324 PUSH_PROMISE_FLAG_END_PUSH_PROMISE = 0x04,
325 PUSH_PROMISE_FLAG_PADDED = 0x08,
328 // Flags on the SETTINGS control frame.
329 enum SpdySettingsControlFlags {
330 SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS = 0x01,
333 enum Http2SettingsControlFlags {
334 SETTINGS_FLAG_ACK = 0x01,
337 // Flags for settings within a SETTINGS frame.
338 enum SpdySettingsFlags {
339 SETTINGS_FLAG_NONE = 0x00,
340 SETTINGS_FLAG_PLEASE_PERSIST = 0x01,
341 SETTINGS_FLAG_PERSISTED = 0x02,
344 // List of known settings. Avoid changing these enum values, as persisted
345 // settings are keyed on them, and they are also exposed in net-internals.
346 enum SpdySettingsIds {
347 SETTINGS_UPLOAD_BANDWIDTH = 0x1,
348 SETTINGS_DOWNLOAD_BANDWIDTH = 0x2,
349 // Network round trip time in milliseconds.
350 SETTINGS_ROUND_TRIP_TIME = 0x3,
351 // The maximum number of simultaneous live streams in each direction.
352 SETTINGS_MAX_CONCURRENT_STREAMS = 0x4,
353 // TCP congestion window in packets.
354 SETTINGS_CURRENT_CWND = 0x5,
355 // Downstream byte retransmission rate in percentage.
356 SETTINGS_DOWNLOAD_RETRANS_RATE = 0x6,
357 // Initial window size in bytes
358 SETTINGS_INITIAL_WINDOW_SIZE = 0x7,
359 // HPACK header table maximum size.
360 SETTINGS_HEADER_TABLE_SIZE = 0x8,
361 // Whether or not server push (PUSH_PROMISE) is enabled.
362 SETTINGS_ENABLE_PUSH = 0x9,
365 // Status codes for RST_STREAM frames.
366 enum SpdyRstStreamStatus {
367 RST_STREAM_INVALID = 0,
368 RST_STREAM_PROTOCOL_ERROR = 1,
369 RST_STREAM_INVALID_STREAM = 2,
370 RST_STREAM_STREAM_CLOSED = 2, // Equivalent to INVALID_STREAM
371 RST_STREAM_REFUSED_STREAM = 3,
372 RST_STREAM_UNSUPPORTED_VERSION = 4,
373 RST_STREAM_CANCEL = 5,
374 RST_STREAM_INTERNAL_ERROR = 6,
375 RST_STREAM_FLOW_CONTROL_ERROR = 7,
376 RST_STREAM_STREAM_IN_USE = 8,
377 RST_STREAM_STREAM_ALREADY_CLOSED = 9,
378 RST_STREAM_INVALID_CREDENTIALS = 10,
379 // FRAME_TOO_LARGE (defined by SPDY versions 3.1 and below), and
380 // FRAME_SIZE_ERROR (defined by HTTP/2) are mapped to the same internal
381 // reset status.
382 RST_STREAM_FRAME_TOO_LARGE = 11,
383 RST_STREAM_FRAME_SIZE_ERROR = 11,
384 RST_STREAM_SETTINGS_TIMEOUT = 12,
385 RST_STREAM_CONNECT_ERROR = 13,
386 RST_STREAM_ENHANCE_YOUR_CALM = 14,
387 RST_STREAM_NUM_STATUS_CODES = 15
390 // Status codes for GOAWAY frames.
391 enum SpdyGoAwayStatus {
392 GOAWAY_OK = 0,
393 GOAWAY_NO_ERROR = GOAWAY_OK,
394 GOAWAY_PROTOCOL_ERROR = 1,
395 GOAWAY_INTERNAL_ERROR = 2,
396 GOAWAY_FLOW_CONTROL_ERROR = 3,
397 GOAWAY_SETTINGS_TIMEOUT = 4,
398 GOAWAY_STREAM_CLOSED = 5,
399 GOAWAY_FRAME_SIZE_ERROR = 6,
400 GOAWAY_REFUSED_STREAM = 7,
401 GOAWAY_CANCEL = 8,
402 GOAWAY_COMPRESSION_ERROR = 9,
403 GOAWAY_CONNECT_ERROR = 10,
404 GOAWAY_ENHANCE_YOUR_CALM = 11,
405 GOAWAY_INADEQUATE_SECURITY = 12
408 // A SPDY priority is a number between 0 and 7 (inclusive).
409 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a
410 // number between 0 and 3.
411 typedef uint8 SpdyPriority;
413 typedef std::map<std::string, std::string> SpdyNameValueBlock;
415 typedef uint64 SpdyPingId;
417 typedef std::string SpdyProtocolId;
419 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any,
420 // but is good to do anyway.
421 class NET_EXPORT_PRIVATE SpdyConstants {
422 public:
423 // Returns true if a given on-the-wire enumeration of a frame type is valid
424 // for a given protocol version, false otherwise.
425 static bool IsValidFrameType(SpdyMajorVersion version, int frame_type_field);
427 // Parses a frame type from an on-the-wire enumeration of a given protocol
428 // version.
429 // Behavior is undefined for invalid frame type fields; consumers should first
430 // use IsValidFrameType() to verify validity of frame type fields.
431 static SpdyFrameType ParseFrameType(SpdyMajorVersion version,
432 int frame_type_field);
434 // Serializes a given frame type to the on-the-wire enumeration value for the
435 // given protocol version.
436 // Returns -1 on failure (I.E. Invalid frame type for the given version).
437 static int SerializeFrameType(SpdyMajorVersion version,
438 SpdyFrameType frame_type);
440 // Returns the frame type for non-control (i.e. data) frames
441 // in the given SPDY version.
442 static int DataFrameType(SpdyMajorVersion version);
444 // Returns true if a given on-the-wire enumeration of a setting id is valid
445 // for a given protocol version, false otherwise.
446 static bool IsValidSettingId(SpdyMajorVersion version, int setting_id_field);
448 // Parses a setting id from an on-the-wire enumeration of a given protocol
449 // version.
450 // Behavior is undefined for invalid setting id fields; consumers should first
451 // use IsValidSettingId() to verify validity of setting id fields.
452 static SpdySettingsIds ParseSettingId(SpdyMajorVersion version,
453 int setting_id_field);
455 // Serializes a given setting id to the on-the-wire enumeration value for the
456 // given protocol version.
457 // Returns -1 on failure (I.E. Invalid setting id for the given version).
458 static int SerializeSettingId(SpdyMajorVersion version, SpdySettingsIds id);
460 // Returns true if a given on-the-wire enumeration of a RST_STREAM status code
461 // is valid for a given protocol version, false otherwise.
462 static bool IsValidRstStreamStatus(SpdyMajorVersion version,
463 int rst_stream_status_field);
465 // Parses a RST_STREAM status code from an on-the-wire enumeration of a given
466 // protocol version.
467 // Behavior is undefined for invalid RST_STREAM status code fields; consumers
468 // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM
469 // status code fields..
470 static SpdyRstStreamStatus ParseRstStreamStatus(SpdyMajorVersion version,
471 int rst_stream_status_field);
473 // Serializes a given RST_STREAM status code to the on-the-wire enumeration
474 // value for the given protocol version.
475 // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given
476 // version).
477 static int SerializeRstStreamStatus(SpdyMajorVersion version,
478 SpdyRstStreamStatus rst_stream_status);
480 // Returns true if a given on-the-wire enumeration of a GOAWAY status code is
481 // valid for the given protocol version, false otherwise.
482 static bool IsValidGoAwayStatus(SpdyMajorVersion version,
483 int goaway_status_field);
485 // Parses a GOAWAY status from an on-the-wire enumeration of a given protocol
486 // version.
487 // Behavior is undefined for invalid GOAWAY status fields; consumers should
488 // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields.
489 static SpdyGoAwayStatus ParseGoAwayStatus(SpdyMajorVersion version,
490 int goaway_status_field);
492 // Serializes a given GOAWAY status to the on-the-wire enumeration value for
493 // the given protocol version.
494 // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version).
495 static int SerializeGoAwayStatus(SpdyMajorVersion version,
496 SpdyGoAwayStatus status);
498 // Size, in bytes, of the data frame header. Future versions of SPDY
499 // will likely vary this, so we allow for the flexibility of a function call
500 // for this value as opposed to a constant.
501 static size_t GetDataFrameMinimumSize();
503 // Size, in bytes, of the control frame header.
504 static size_t GetControlFrameHeaderSize(SpdyMajorVersion version);
506 static size_t GetPrefixLength(SpdyFrameType type, SpdyMajorVersion version);
508 static size_t GetFrameMaximumSize(SpdyMajorVersion version);
510 // Returns the size of a header block size field. Valid only for SPDY
511 // versions <= 3.
512 static size_t GetSizeOfSizeField(SpdyMajorVersion version);
514 // Returns the size (in bytes) of a wire setting ID and value.
515 static size_t GetSettingSize(SpdyMajorVersion version);
517 static SpdyMajorVersion ParseMajorVersion(int version_number);
519 static int SerializeMajorVersion(SpdyMajorVersion version);
521 static std::string GetVersionString(SpdyMajorVersion version);
524 class SpdyFrame;
525 typedef SpdyFrame SpdySerializedFrame;
527 class SpdyFrameVisitor;
529 // Intermediate representation for SPDY frames.
530 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is
531 // gone.
532 class NET_EXPORT_PRIVATE SpdyFrameIR {
533 public:
534 virtual ~SpdyFrameIR() {}
536 virtual void Visit(SpdyFrameVisitor* visitor) const = 0;
538 protected:
539 SpdyFrameIR() {}
541 private:
542 DISALLOW_COPY_AND_ASSIGN(SpdyFrameIR);
545 // Abstract class intended to be inherited by IRs that have a stream associated
546 // to them.
547 class NET_EXPORT_PRIVATE SpdyFrameWithStreamIdIR : public SpdyFrameIR {
548 public:
549 virtual ~SpdyFrameWithStreamIdIR() {}
550 SpdyStreamId stream_id() const { return stream_id_; }
551 void set_stream_id(SpdyStreamId stream_id) {
552 DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
553 stream_id_ = stream_id;
556 protected:
557 explicit SpdyFrameWithStreamIdIR(SpdyStreamId stream_id) {
558 set_stream_id(stream_id);
561 private:
562 SpdyStreamId stream_id_;
564 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithStreamIdIR);
567 // Abstract class intended to be inherited by IRs that have the option of a FIN
568 // flag. Implies SpdyFrameWithStreamIdIR.
569 class NET_EXPORT_PRIVATE SpdyFrameWithFinIR : public SpdyFrameWithStreamIdIR {
570 public:
571 virtual ~SpdyFrameWithFinIR() {}
572 bool fin() const { return fin_; }
573 void set_fin(bool fin) { fin_ = fin; }
575 protected:
576 explicit SpdyFrameWithFinIR(SpdyStreamId stream_id)
577 : SpdyFrameWithStreamIdIR(stream_id),
578 fin_(false) {}
580 private:
581 bool fin_;
583 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithFinIR);
586 // Abstract class intended to be inherited by IRs that contain a name-value
587 // block. Implies SpdyFrameWithFinIR.
588 class NET_EXPORT_PRIVATE SpdyFrameWithNameValueBlockIR
589 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) {
590 public:
591 const SpdyNameValueBlock& name_value_block() const {
592 return name_value_block_;
594 void set_name_value_block(const SpdyNameValueBlock& name_value_block) {
595 // Deep copy.
596 name_value_block_ = name_value_block;
598 void SetHeader(const base::StringPiece& name,
599 const base::StringPiece& value) {
600 name_value_block_[name.as_string()] = value.as_string();
602 SpdyNameValueBlock* mutable_name_value_block() {
603 return &name_value_block_;
606 protected:
607 explicit SpdyFrameWithNameValueBlockIR(SpdyStreamId stream_id);
608 virtual ~SpdyFrameWithNameValueBlockIR();
610 private:
611 SpdyNameValueBlock name_value_block_;
613 DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithNameValueBlockIR);
616 class NET_EXPORT_PRIVATE SpdyDataIR
617 : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) {
618 public:
619 // Performs deep copy on data.
620 SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data);
622 // Use in conjunction with SetDataShallow() for shallow-copy on data.
623 explicit SpdyDataIR(SpdyStreamId stream_id);
625 virtual ~SpdyDataIR();
627 base::StringPiece data() const { return data_; }
629 bool padded() const { return padded_; }
631 int padding_payload_len() const { return padding_payload_len_; }
633 void set_padding_len(int padding_len) {
634 DCHECK_GT(padding_len, 0);
635 DCHECK_LE(padding_len, kPaddingSizePerFrame);
636 padded_ = true;
637 // The pad field takes one octet on the wire.
638 padding_payload_len_ = padding_len - 1;
641 // Deep-copy of data (keep private copy).
642 void SetDataDeep(const base::StringPiece& data) {
643 data_store_.reset(new std::string(data.data(), data.length()));
644 data_ = *(data_store_.get());
647 // Shallow-copy of data (do not keep private copy).
648 void SetDataShallow(const base::StringPiece& data) {
649 data_store_.reset();
650 data_ = data;
653 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
655 private:
656 // Used to store data that this SpdyDataIR should own.
657 scoped_ptr<std::string> data_store_;
658 base::StringPiece data_;
660 bool padded_;
661 // padding_payload_len_ = desired padding length - len(padding length field).
662 int padding_payload_len_;
664 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR);
667 class NET_EXPORT_PRIVATE SpdySynStreamIR
668 : public SpdyFrameWithNameValueBlockIR {
669 public:
670 explicit SpdySynStreamIR(SpdyStreamId stream_id)
671 : SpdyFrameWithNameValueBlockIR(stream_id),
672 associated_to_stream_id_(0),
673 priority_(0),
674 unidirectional_(false) {}
675 SpdyStreamId associated_to_stream_id() const {
676 return associated_to_stream_id_;
678 void set_associated_to_stream_id(SpdyStreamId stream_id) {
679 associated_to_stream_id_ = stream_id;
681 SpdyPriority priority() const { return priority_; }
682 void set_priority(SpdyPriority priority) { priority_ = priority; }
683 bool unidirectional() const { return unidirectional_; }
684 void set_unidirectional(bool unidirectional) {
685 unidirectional_ = unidirectional;
688 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
690 private:
691 SpdyStreamId associated_to_stream_id_;
692 SpdyPriority priority_;
693 bool unidirectional_;
695 DISALLOW_COPY_AND_ASSIGN(SpdySynStreamIR);
698 class NET_EXPORT_PRIVATE SpdySynReplyIR : public SpdyFrameWithNameValueBlockIR {
699 public:
700 explicit SpdySynReplyIR(SpdyStreamId stream_id)
701 : SpdyFrameWithNameValueBlockIR(stream_id) {}
703 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
705 private:
706 DISALLOW_COPY_AND_ASSIGN(SpdySynReplyIR);
709 class NET_EXPORT_PRIVATE SpdyRstStreamIR : public SpdyFrameWithStreamIdIR {
710 public:
711 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyRstStreamStatus status,
712 base::StringPiece description);
714 virtual ~SpdyRstStreamIR();
716 SpdyRstStreamStatus status() const {
717 return status_;
719 void set_status(SpdyRstStreamStatus status) {
720 status_ = status;
723 base::StringPiece description() const { return description_; }
725 void set_description(base::StringPiece description) {
726 description_ = description;
729 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
731 private:
732 SpdyRstStreamStatus status_;
733 base::StringPiece description_;
735 DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR);
738 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR {
739 public:
740 // Associates flags with a value.
741 struct Value {
742 Value() : persist_value(false),
743 persisted(false),
744 value(0) {}
745 bool persist_value;
746 bool persisted;
747 int32 value;
749 typedef std::map<SpdySettingsIds, Value> ValueMap;
751 SpdySettingsIR();
753 virtual ~SpdySettingsIR();
755 // Overwrites as appropriate.
756 const ValueMap& values() const { return values_; }
757 void AddSetting(SpdySettingsIds id,
758 bool persist_value,
759 bool persisted,
760 int32 value) {
761 values_[id].persist_value = persist_value;
762 values_[id].persisted = persisted;
763 values_[id].value = value;
766 bool clear_settings() const { return clear_settings_; }
767 void set_clear_settings(bool clear_settings) {
768 clear_settings_ = clear_settings;
770 bool is_ack() const { return is_ack_; }
771 void set_is_ack(bool is_ack) {
772 is_ack_ = is_ack;
775 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
777 private:
778 ValueMap values_;
779 bool clear_settings_;
780 bool is_ack_;
782 DISALLOW_COPY_AND_ASSIGN(SpdySettingsIR);
785 class NET_EXPORT_PRIVATE SpdyPingIR : public SpdyFrameIR {
786 public:
787 explicit SpdyPingIR(SpdyPingId id) : id_(id), is_ack_(false) {}
788 SpdyPingId id() const { return id_; }
790 // ACK logic is valid only for SPDY versions 4 and above.
791 bool is_ack() const { return is_ack_; }
792 void set_is_ack(bool is_ack) { is_ack_ = is_ack; }
794 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
796 private:
797 SpdyPingId id_;
798 bool is_ack_;
800 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR);
803 class NET_EXPORT_PRIVATE SpdyGoAwayIR : public SpdyFrameIR {
804 public:
805 SpdyGoAwayIR(SpdyStreamId last_good_stream_id, SpdyGoAwayStatus status,
806 const base::StringPiece& description);
807 virtual ~SpdyGoAwayIR();
808 SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; }
809 void set_last_good_stream_id(SpdyStreamId last_good_stream_id) {
810 DCHECK_LE(0u, last_good_stream_id);
811 DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask);
812 last_good_stream_id_ = last_good_stream_id;
814 SpdyGoAwayStatus status() const { return status_; }
815 void set_status(SpdyGoAwayStatus status) {
816 // TODO(hkhalil): Check valid ranges of status?
817 status_ = status;
820 const base::StringPiece& description() const;
822 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
824 private:
825 SpdyStreamId last_good_stream_id_;
826 SpdyGoAwayStatus status_;
827 const base::StringPiece description_;
829 DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR);
832 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithNameValueBlockIR {
833 public:
834 explicit SpdyHeadersIR(SpdyStreamId stream_id)
835 : SpdyFrameWithNameValueBlockIR(stream_id),
836 has_priority_(false),
837 priority_(0) {}
839 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
841 bool has_priority() const { return has_priority_; }
842 void set_has_priority(bool has_priority) { has_priority_ = has_priority; }
843 uint32 priority() const { return priority_; }
844 void set_priority(SpdyPriority priority) { priority_ = priority; }
846 private:
847 bool has_priority_;
848 // 31-bit priority.
849 uint32 priority_;
850 DISALLOW_COPY_AND_ASSIGN(SpdyHeadersIR);
853 class NET_EXPORT_PRIVATE SpdyWindowUpdateIR : public SpdyFrameWithStreamIdIR {
854 public:
855 SpdyWindowUpdateIR(SpdyStreamId stream_id, int32 delta)
856 : SpdyFrameWithStreamIdIR(stream_id) {
857 set_delta(delta);
859 int32 delta() const { return delta_; }
860 void set_delta(int32 delta) {
861 DCHECK_LT(0, delta);
862 DCHECK_LE(delta, kSpdyMaximumWindowSize);
863 delta_ = delta;
866 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
868 private:
869 int32 delta_;
871 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateIR);
874 class NET_EXPORT_PRIVATE SpdyBlockedIR
875 : public NON_EXPORTED_BASE(SpdyFrameWithStreamIdIR) {
876 public:
877 explicit SpdyBlockedIR(SpdyStreamId stream_id)
878 : SpdyFrameWithStreamIdIR(stream_id) {}
880 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
882 private:
883 DISALLOW_COPY_AND_ASSIGN(SpdyBlockedIR);
886 class NET_EXPORT_PRIVATE SpdyPushPromiseIR
887 : public SpdyFrameWithNameValueBlockIR {
888 public:
889 SpdyPushPromiseIR(SpdyStreamId stream_id, SpdyStreamId promised_stream_id)
890 : SpdyFrameWithNameValueBlockIR(stream_id),
891 promised_stream_id_(promised_stream_id) {}
892 SpdyStreamId promised_stream_id() const { return promised_stream_id_; }
893 void set_promised_stream_id(SpdyStreamId id) { promised_stream_id_ = id; }
895 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
897 private:
898 SpdyStreamId promised_stream_id_;
899 DISALLOW_COPY_AND_ASSIGN(SpdyPushPromiseIR);
902 // TODO(jgraettinger): This representation needs review. SpdyContinuationIR
903 // needs to frame a portion of a single, arbitrarily-broken encoded buffer.
904 class NET_EXPORT_PRIVATE SpdyContinuationIR
905 : public SpdyFrameWithNameValueBlockIR {
906 public:
907 explicit SpdyContinuationIR(SpdyStreamId stream_id)
908 : SpdyFrameWithNameValueBlockIR(stream_id),
909 end_headers_(false) {}
911 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
913 bool end_headers() const { return end_headers_; }
914 void set_end_headers(bool end_headers) {end_headers_ = end_headers;}
916 private:
917 bool end_headers_;
918 DISALLOW_COPY_AND_ASSIGN(SpdyContinuationIR);
921 class NET_EXPORT_PRIVATE SpdyAltSvcIR : public SpdyFrameWithStreamIdIR {
922 public:
923 explicit SpdyAltSvcIR(SpdyStreamId stream_id);
925 uint32 max_age() const { return max_age_; }
926 uint16 port() const { return port_; }
927 SpdyProtocolId protocol_id() const {
928 return protocol_id_;
930 std::string host() const { return host_; }
931 std::string origin() const { return origin_; }
933 void set_max_age(uint32 max_age) { max_age_ = max_age; }
934 void set_port(uint16 port) { port_ = port; }
935 void set_protocol_id(SpdyProtocolId protocol_id) {
936 protocol_id_ = protocol_id;
938 void set_host(std::string host) {
939 host_ = host;
941 void set_origin(std::string origin) {
942 origin_ = origin;
945 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
947 private:
948 uint32 max_age_;
949 uint16 port_;
950 SpdyProtocolId protocol_id_;
951 std::string host_;
952 std::string origin_;
953 DISALLOW_COPY_AND_ASSIGN(SpdyAltSvcIR);
956 class NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR {
957 public:
958 explicit SpdyPriorityIR(SpdyStreamId stream_id);
959 explicit SpdyPriorityIR(SpdyStreamId stream_id,
960 SpdyStreamId parent_stream_id,
961 uint8 weight,
962 bool exclusive);
963 SpdyStreamId parent_stream_id() const { return parent_stream_id_; }
964 void set_parent_stream_id(SpdyStreamId id) { parent_stream_id_ = id; }
965 uint8 weight() const { return weight_; }
966 void set_weight(uint8 weight) { weight_ = weight; }
967 bool exclusive() const { return exclusive_; }
968 void set_exclusive(bool exclusive) { exclusive_ = exclusive; }
970 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
972 private:
973 SpdyStreamId parent_stream_id_;
974 uint8 weight_;
975 bool exclusive_;
976 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR);
979 // -------------------------------------------------------------------------
980 // Wrapper classes for various SPDY frames.
982 // All Spdy Frame types derive from this SpdyFrame class.
983 class SpdyFrame {
984 public:
985 // Create a SpdyFrame using a pre-created buffer.
986 // If |owns_buffer| is true, this class takes ownership of the buffer
987 // and will delete it on cleanup. The buffer must have been created using
988 // new char[].
989 // If |owns_buffer| is false, the caller retains ownership of the buffer and
990 // is responsible for making sure the buffer outlives this frame. In other
991 // words, this class does NOT create a copy of the buffer.
992 SpdyFrame(char* data, size_t size, bool owns_buffer)
993 : frame_(data),
994 size_(size),
995 owns_buffer_(owns_buffer) {
996 DCHECK(frame_);
999 ~SpdyFrame() {
1000 if (owns_buffer_) {
1001 delete [] frame_;
1003 frame_ = NULL;
1006 // Provides access to the frame bytes, which is a buffer containing
1007 // the frame packed as expected for sending over the wire.
1008 char* data() const { return frame_; }
1010 // Returns the actual size of the underlying buffer.
1011 size_t size() const { return size_; }
1013 protected:
1014 char* frame_;
1016 private:
1017 size_t size_;
1018 bool owns_buffer_;
1019 DISALLOW_COPY_AND_ASSIGN(SpdyFrame);
1022 // This interface is for classes that want to process SpdyFrameIRs without
1023 // having to know what type they are. An instance of this interface can be
1024 // passed to a SpdyFrameIR's Visit method, and the appropriate type-specific
1025 // method of this class will be called.
1026 class SpdyFrameVisitor {
1027 public:
1028 virtual void VisitSynStream(const SpdySynStreamIR& syn_stream) = 0;
1029 virtual void VisitSynReply(const SpdySynReplyIR& syn_reply) = 0;
1030 virtual void VisitRstStream(const SpdyRstStreamIR& rst_stream) = 0;
1031 virtual void VisitSettings(const SpdySettingsIR& settings) = 0;
1032 virtual void VisitPing(const SpdyPingIR& ping) = 0;
1033 virtual void VisitGoAway(const SpdyGoAwayIR& goaway) = 0;
1034 virtual void VisitHeaders(const SpdyHeadersIR& headers) = 0;
1035 virtual void VisitWindowUpdate(const SpdyWindowUpdateIR& window_update) = 0;
1036 virtual void VisitBlocked(const SpdyBlockedIR& blocked) = 0;
1037 virtual void VisitPushPromise(const SpdyPushPromiseIR& push_promise) = 0;
1038 virtual void VisitContinuation(const SpdyContinuationIR& continuation) = 0;
1039 virtual void VisitAltSvc(const SpdyAltSvcIR& altsvc) = 0;
1040 virtual void VisitPriority(const SpdyPriorityIR& priority) = 0;
1041 virtual void VisitData(const SpdyDataIR& data) = 0;
1043 protected:
1044 SpdyFrameVisitor() {}
1045 virtual ~SpdyFrameVisitor() {}
1047 private:
1048 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor);
1051 } // namespace net
1053 #endif // NET_SPDY_SPDY_PROTOCOL_H_