15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This file contains some protocol structures for use with SPDY 2 and 3
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The SPDY 2 spec can be found at:
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft2
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The SPDY 3 spec can be found at:
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_SPDY_SPDY_PROTOCOL_H_
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_SPDY_SPDY_PROTOCOL_H_
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <map>
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector>
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/strings/string_piece.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/sys_byteorder.h"
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/net_export.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/spdy/spdy_bitmasks.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// The major versions of SPDY. Major version differences indicate
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// framer-layer incompatibility, as opposed to minor version numbers
315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// which indicate application-layer incompatibility. Do not rely on
325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// the mapping from enum value SPDYn to the integer n.
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)enum SpdyMajorVersion {
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SPDY2 = 2,
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SPDY_MIN_VERSION = SPDY2,
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SPDY3 = 3,
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SPDY4 = 4,
385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  SPDY5 = 5,
395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  SPDY_MAX_VERSION = SPDY5
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A SPDY stream id is a 31 bit entity.
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef uint32 SpdyStreamId;
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Specifies the stream ID used to denote the current session (for
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// flow control).
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const SpdyStreamId kSessionFlowControlStreamId = 0;
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Initial window size for a Spdy stream in bytes.
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int32 kSpdyStreamInitialWindowSize = 64 * 1024;  // 64 KBytes
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// The maxmium possible control frame size allowed by the spec.
5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const int32 kSpdyMaxControlFrameSize = (1 << 24) - 1;
5403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
5503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// The maximum control frame size we actually send/accept.
5603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const int32 kControlFrameSizeLimit = 1 << 14;
5703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Initial window size for a Spdy session in bytes.
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int32 kSpdySessionInitialWindowSize = 64 * 1024;  // 64 KBytes
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Maximum window size for a Spdy stream or session.
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int32 kSpdyMaximumWindowSize = 0x7FFFFFFF;  // Max signed 32bit int
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Maximum padding size in octets for one DATA or HEADERS or PUSH_PROMISE frame.
65116680a4aac90f2aa7413d9095a592090648e557Ben Murdochconst int32 kPaddingSizePerFrame = 256;
66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SPDY 2 dictionary.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is just a hacked dictionary to use for shrinking HTTP-like headers.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kV2Dictionary[] =
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-"
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi"
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser"
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "-agent10010120020120220320420520630030130230330430530630740040140240340440"
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "5406407408409410411412413414415416417500501502503504505accept-rangesageeta"
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic"
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran"
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati"
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo"
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe"
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic"
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  "ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1"
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ".1statusversionurl";
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kV2DictionarySize = arraysize(kV2Dictionary);
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SPDY 3 dictionary.
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kV3Dictionary[] = {
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x07, 0x6f, 0x70, 0x74, 0x69,  // ....opti
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6f, 0x6e, 0x73, 0x00, 0x00, 0x00, 0x04, 0x68,  // ons....h
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x61, 0x64, 0x00, 0x00, 0x00, 0x04, 0x70,  // ead....p
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x03, 0x70,  // ost....p
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x75, 0x74, 0x00, 0x00, 0x00, 0x06, 0x64, 0x65,  // ut....de
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6c, 0x65, 0x74, 0x65, 0x00, 0x00, 0x00, 0x05,  // lete....
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x72, 0x61, 0x63, 0x65, 0x00, 0x00, 0x00,  // trace...
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x06, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x00,  // .accept.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70,  // ...accep
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x2d, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65,  // t-charse
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x63, 0x63,  // t....acc
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x70, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f,  // ept-enco
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x0f,  // ding....
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x6c,  // accept-l
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65, 0x00,  // anguage.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x0d, 0x61, 0x63, 0x63, 0x65, 0x70,  // ...accep
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x73,  // t-ranges
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x03, 0x61, 0x67, 0x65, 0x00,  // ....age.
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x05, 0x61, 0x6c, 0x6c, 0x6f, 0x77,  // ...allow
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x0d, 0x61, 0x75, 0x74, 0x68,  // ....auth
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f,  // orizatio
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6e, 0x00, 0x00, 0x00, 0x0d, 0x63, 0x61, 0x63,  // n....cac
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x68, 0x65, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72,  // he-contr
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6f, 0x6c, 0x00, 0x00, 0x00, 0x0a, 0x63, 0x6f,  // ol....co
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,  // nnection
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74,  // ....cont
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x6e, 0x74, 0x2d, 0x62, 0x61, 0x73, 0x65,  // ent-base
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x10, 0x63, 0x6f, 0x6e, 0x74,  // ....cont
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x6e, 0x74, 0x2d, 0x65, 0x6e, 0x63, 0x6f,  // ent-enco
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x64, 0x69, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x10,  // ding....
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d,  // content-
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67, 0x65,  // language
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x0e, 0x63, 0x6f, 0x6e, 0x74,  // ....cont
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x65, 0x6e, 0x67,  // ent-leng
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x68, 0x00, 0x00, 0x00, 0x10, 0x63, 0x6f,  // th....co
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x6f,  // ntent-lo
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00,  // cation..
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e,  // ..conten
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x2d, 0x6d, 0x64, 0x35, 0x00, 0x00, 0x00,  // t-md5...
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,  // .content
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2d, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00,  // -range..
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e,  // ..conten
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00,  // t-type..
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x04, 0x64, 0x61, 0x74, 0x65, 0x00, 0x00,  // ..date..
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x04, 0x65, 0x74, 0x61, 0x67, 0x00, 0x00,  // ..etag..
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x06, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74,  // ..expect
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x07, 0x65, 0x78, 0x70, 0x69,  // ....expi
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x72, 0x65, 0x73, 0x00, 0x00, 0x00, 0x04, 0x66,  // res....f
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x72, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x04, 0x68,  // rom....h
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6f, 0x73, 0x74, 0x00, 0x00, 0x00, 0x08, 0x69,  // ost....i
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x66, 0x2d, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00,  // f-match.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x11, 0x69, 0x66, 0x2d, 0x6d, 0x6f,  // ...if-mo
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x2d, 0x73,  // dified-s
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x69, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x0d,  // ince....
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x69, 0x66, 0x2d, 0x6e, 0x6f, 0x6e, 0x65, 0x2d,  // if-none-
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, 0x00, 0x00,  // match...
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x08, 0x69, 0x66, 0x2d, 0x72, 0x61, 0x6e, 0x67,  // .if-rang
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x00, 0x00, 0x00, 0x13, 0x69, 0x66, 0x2d,  // e....if-
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x75, 0x6e, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69,  // unmodifi
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x64, 0x2d, 0x73, 0x69, 0x6e, 0x63, 0x65,  // ed-since
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x0d, 0x6c, 0x61, 0x73, 0x74,  // ....last
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2d, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65,  // -modifie
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x64, 0x00, 0x00, 0x00, 0x08, 0x6c, 0x6f, 0x63,  // d....loc
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00,  // ation...
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x0c, 0x6d, 0x61, 0x78, 0x2d, 0x66, 0x6f, 0x72,  // .max-for
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x77, 0x61, 0x72, 0x64, 0x73, 0x00, 0x00, 0x00,  // wards...
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x06, 0x70, 0x72, 0x61, 0x67, 0x6d, 0x61, 0x00,  // .pragma.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x12, 0x70, 0x72, 0x6f, 0x78, 0x79,  // ...proxy
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74,  // -authent
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00,  // icate...
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x13, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2d, 0x61,  // .proxy-a
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61,  // uthoriza
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05,  // tion....
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x00, 0x00,  // range...
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x07, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72,  // .referer
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x0b, 0x72, 0x65, 0x74, 0x72,  // ....retr
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x79, 0x2d, 0x61, 0x66, 0x74, 0x65, 0x72, 0x00,  // y-after.
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65,  // ...serve
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x72, 0x00, 0x00, 0x00, 0x02, 0x74, 0x65, 0x00,  // r....te.
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x07, 0x74, 0x72, 0x61, 0x69, 0x6c,  // ...trail
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x72, 0x00, 0x00, 0x00, 0x11, 0x74, 0x72,  // er....tr
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x2d, 0x65,  // ansfer-e
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x00,  // ncoding.
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x07, 0x75, 0x70, 0x67, 0x72, 0x61,  // ...upgra
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x64, 0x65, 0x00, 0x00, 0x00, 0x0a, 0x75, 0x73,  // de....us
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x72, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74,  // er-agent
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x04, 0x76, 0x61, 0x72, 0x79,  // ....vary
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x03, 0x76, 0x69, 0x61, 0x00,  // ....via.
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x07, 0x77, 0x61, 0x72, 0x6e, 0x69,  // ...warni
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6e, 0x67, 0x00, 0x00, 0x00, 0x10, 0x77, 0x77,  // ng....ww
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x77, 0x2d, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e,  // w-authen
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x00,  // ticate..
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64,  // ..method
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x00, 0x03, 0x67, 0x65, 0x74, 0x00,  // ....get.
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75,  // ...statu
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x73, 0x00, 0x00, 0x00, 0x06, 0x32, 0x30, 0x30,  // s....200
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x20, 0x4f, 0x4b, 0x00, 0x00, 0x00, 0x07, 0x76,  // .OK....v
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, 0x00,  // ersion..
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x08, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31,  // ..HTTP.1
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2e, 0x31, 0x00, 0x00, 0x00, 0x03, 0x75, 0x72,  // .1....ur
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6c, 0x00, 0x00, 0x00, 0x06, 0x70, 0x75, 0x62,  // l....pub
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6c, 0x69, 0x63, 0x00, 0x00, 0x00, 0x0a, 0x73,  // lic....s
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x74, 0x2d, 0x63, 0x6f, 0x6f, 0x6b, 0x69,  // et-cooki
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x00, 0x00, 0x00, 0x0a, 0x6b, 0x65, 0x65,  // e....kee
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x70, 0x2d, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x00,  // p-alive.
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x00, 0x00, 0x06, 0x6f, 0x72, 0x69, 0x67, 0x69,  // ...origi
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6e, 0x31, 0x30, 0x30, 0x31, 0x30, 0x31, 0x32,  // n1001012
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x30, 0x31, 0x32, 0x30, 0x32, 0x32, 0x30, 0x35,  // 01202205
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x32, 0x30, 0x36, 0x33, 0x30, 0x30, 0x33, 0x30,  // 20630030
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x32, 0x33, 0x30, 0x33, 0x33, 0x30, 0x34, 0x33,  // 23033043
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x30, 0x35, 0x33, 0x30, 0x36, 0x33, 0x30, 0x37,  // 05306307
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x34, 0x30, 0x32, 0x34, 0x30, 0x35, 0x34, 0x30,  // 40240540
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x36, 0x34, 0x30, 0x37, 0x34, 0x30, 0x38, 0x34,  // 64074084
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x30, 0x39, 0x34, 0x31, 0x30, 0x34, 0x31, 0x31,  // 09410411
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x34, 0x31, 0x32, 0x34, 0x31, 0x33, 0x34, 0x31,  // 41241341
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x34, 0x34, 0x31, 0x35, 0x34, 0x31, 0x36, 0x34,  // 44154164
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x31, 0x37, 0x35, 0x30, 0x32, 0x35, 0x30, 0x34,  // 17502504
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x35, 0x30, 0x35, 0x32, 0x30, 0x33, 0x20, 0x4e,  // 505203.N
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6f, 0x6e, 0x2d, 0x41, 0x75, 0x74, 0x68, 0x6f,  // on-Autho
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x72, 0x69, 0x74, 0x61, 0x74, 0x69, 0x76, 0x65,  // ritative
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x20, 0x49, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61,  // .Informa
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x69, 0x6f, 0x6e, 0x32, 0x30, 0x34, 0x20,  // tion204.
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x4e, 0x6f, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x65,  // No.Conte
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6e, 0x74, 0x33, 0x30, 0x31, 0x20, 0x4d, 0x6f,  // nt301.Mo
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x76, 0x65, 0x64, 0x20, 0x50, 0x65, 0x72, 0x6d,  // ved.Perm
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x61, 0x6e, 0x65, 0x6e, 0x74, 0x6c, 0x79, 0x34,  // anently4
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x30, 0x30, 0x20, 0x42, 0x61, 0x64, 0x20, 0x52,  // 00.Bad.R
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x34, 0x30,  // equest40
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x31, 0x20, 0x55, 0x6e, 0x61, 0x75, 0x74, 0x68,  // 1.Unauth
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64, 0x34, 0x30,  // orized40
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x33, 0x20, 0x46, 0x6f, 0x72, 0x62, 0x69, 0x64,  // 3.Forbid
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x64, 0x65, 0x6e, 0x34, 0x30, 0x34, 0x20, 0x4e,  // den404.N
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6f, 0x74, 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64,  // ot.Found
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x35, 0x30, 0x30, 0x20, 0x49, 0x6e, 0x74, 0x65,  // 500.Inte
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x72, 0x6e, 0x61, 0x6c, 0x20, 0x53, 0x65, 0x72,  // rnal.Ser
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x76, 0x65, 0x72, 0x20, 0x45, 0x72, 0x72, 0x6f,  // ver.Erro
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x72, 0x35, 0x30, 0x31, 0x20, 0x4e, 0x6f, 0x74,  // r501.Not
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x20, 0x49, 0x6d, 0x70, 0x6c, 0x65, 0x6d, 0x65,  // .Impleme
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6e, 0x74, 0x65, 0x64, 0x35, 0x30, 0x33, 0x20,  // nted503.
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20,  // Service.
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x55, 0x6e, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61,  // Unavaila
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x62, 0x6c, 0x65, 0x4a, 0x61, 0x6e, 0x20, 0x46,  // bleJan.F
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x62, 0x20, 0x4d, 0x61, 0x72, 0x20, 0x41,  // eb.Mar.A
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x70, 0x72, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x4a,  // pr.May.J
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x75, 0x6e, 0x20, 0x4a, 0x75, 0x6c, 0x20, 0x41,  // un.Jul.A
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x75, 0x67, 0x20, 0x53, 0x65, 0x70, 0x74, 0x20,  // ug.Sept.
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x4f, 0x63, 0x74, 0x20, 0x4e, 0x6f, 0x76, 0x20,  // Oct.Nov.
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x44, 0x65, 0x63, 0x20, 0x30, 0x30, 0x3a, 0x30,  // Dec.00.0
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x30, 0x3a, 0x30, 0x30, 0x20, 0x4d, 0x6f, 0x6e,  // 0.00.Mon
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2c, 0x20, 0x54, 0x75, 0x65, 0x2c, 0x20, 0x57,  // ..Tue..W
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x64, 0x2c, 0x20, 0x54, 0x68, 0x75, 0x2c,  // ed..Thu.
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x20, 0x46, 0x72, 0x69, 0x2c, 0x20, 0x53, 0x61,  // .Fri..Sa
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x2c, 0x20, 0x53, 0x75, 0x6e, 0x2c, 0x20,  // t..Sun..
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x47, 0x4d, 0x54, 0x63, 0x68, 0x75, 0x6e, 0x6b,  // GMTchunk
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x64, 0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f,  // ed.text.
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x68, 0x74, 0x6d, 0x6c, 0x2c, 0x69, 0x6d, 0x61,  // html.ima
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x2c, 0x69,  // ge.png.i
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6d, 0x61, 0x67, 0x65, 0x2f, 0x6a, 0x70, 0x67,  // mage.jpg
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2c, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67,  // .image.g
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x69, 0x66, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69,  // if.appli
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78,  // cation.x
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x6d, 0x6c, 0x2c, 0x61, 0x70, 0x70, 0x6c, 0x69,  // ml.appli
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x78,  // cation.x
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x68, 0x74, 0x6d, 0x6c, 0x2b, 0x78, 0x6d, 0x6c,  // html.xml
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2c, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x70, 0x6c,  // .text.pl
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x61, 0x69, 0x6e, 0x2c, 0x74, 0x65, 0x78, 0x74,  // ain.text
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2f, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72,  // .javascr
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x69, 0x70, 0x74, 0x2c, 0x70, 0x75, 0x62, 0x6c,  // ipt.publ
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x69, 0x63, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74,  // icprivat
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x65, 0x6d, 0x61, 0x78, 0x2d, 0x61, 0x67, 0x65,  // emax-age
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x3d, 0x67, 0x7a, 0x69, 0x70, 0x2c, 0x64, 0x65,  // .gzip.de
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x66, 0x6c, 0x61, 0x74, 0x65, 0x2c, 0x73, 0x64,  // flate.sd
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x63, 0x68, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65,  // chcharse
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x74, 0x3d, 0x75, 0x74, 0x66, 0x2d, 0x38, 0x63,  // t.utf-8c
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x3d, 0x69,  // harset.i
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x73, 0x6f, 0x2d, 0x38, 0x38, 0x35, 0x39, 0x2d,  // so-8859-
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x31, 0x2c, 0x75, 0x74, 0x66, 0x2d, 0x2c, 0x2a,  // 1.utf-..
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e         // .enq.0.
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kV3DictionarySize = arraysize(kV3Dictionary);
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
268a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// The HTTP/2 connection header prefix, which must be the first bytes
269a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// sent by the client upon starting an HTTP/2 connection, and which
270a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// must be followed by a SETTINGS frame.
2712385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch//
2722385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Equivalent to the string "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
2732385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// (without the null terminator).
2742385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdochconst char kHttp2ConnectionHeaderPrefix[] = {
2752385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  0x50, 0x52, 0x49, 0x20, 0x2a, 0x20, 0x48, 0x54,  // PRI * HT
2762385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  0x54, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x0d, 0x0a,  // TP/2.0..
2772385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  0x0d, 0x0a, 0x53, 0x4d, 0x0d, 0x0a, 0x0d, 0x0a   // ..SM....
2782385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch};
279a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)const int kHttp2ConnectionHeaderPrefixSize =
280a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    arraysize(kHttp2ConnectionHeaderPrefix);
281a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
28203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const char kHttp2VersionString[] = "HTTP/1.1";
28303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
284c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Types of SPDY frames.
285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)enum SpdyFrameType {
286116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  DATA,
287116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  SYN_STREAM,
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SYN_REPLY,
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RST_STREAM,
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SETTINGS,
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PING,
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GOAWAY,
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HEADERS,
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WINDOW_UPDATE,
295116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  CREDENTIAL = 10,  // No longer valid.  Kept for identifiability.
2967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PUSH_PROMISE,
297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  CONTINUATION,
29803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  PRIORITY,
29903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // BLOCKED and ALTSVC are recognized extensions.
30003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  BLOCKED,
301cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  ALTSVC,
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Flags on data packets.
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum SpdyDataFlags {
306cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DATA_FLAG_NONE = 0x00,
3074ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  DATA_FLAG_FIN = 0x01,
3084ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  DATA_FLAG_END_SEGMENT = 0x02,
309116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  DATA_FLAG_PADDED = 0x08,
310cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DATA_FLAG_COMPRESSED = 0x20,
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Flags on control packets
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum SpdyControlFlags {
315cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  CONTROL_FLAG_NONE = 0x00,
316cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  CONTROL_FLAG_FIN = 0x01,
317cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  CONTROL_FLAG_UNIDIRECTIONAL = 0x02,
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
320a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)enum SpdyPingFlags {
321cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  PING_FLAG_ACK = 0x01,
322a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
323a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
324cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Used by HEADERS, PUSH_PROMISE, and CONTINUATION.
3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)enum SpdyHeadersFlags {
326cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  HEADERS_FLAG_END_SEGMENT = 0x02,
327cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  HEADERS_FLAG_END_HEADERS = 0x04,
328116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  HEADERS_FLAG_PADDED = 0x08,
329cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  HEADERS_FLAG_PRIORITY = 0x20,
330a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
331a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
332a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)enum SpdyPushPromiseFlags {
333cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  PUSH_PROMISE_FLAG_END_PUSH_PROMISE = 0x04,
334116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  PUSH_PROMISE_FLAG_PADDED = 0x08,
3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
3365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Flags on the SETTINGS control frame.
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum SpdySettingsControlFlags {
339cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS = 0x01,
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
342a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)enum Http2SettingsControlFlags {
343cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  SETTINGS_FLAG_ACK = 0x01,
344a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
345a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Flags for settings within a SETTINGS frame.
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum SpdySettingsFlags {
348cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  SETTINGS_FLAG_NONE = 0x00,
349cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  SETTINGS_FLAG_PLEASE_PERSIST = 0x01,
350cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  SETTINGS_FLAG_PERSISTED = 0x02,
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
353e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// List of known settings. Avoid changing these enum values, as persisted
354e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch// settings are keyed on them, and they are also exposed in net-internals.
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum SpdySettingsIds {
356e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_UPLOAD_BANDWIDTH = 0x1,
357e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_DOWNLOAD_BANDWIDTH = 0x2,
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Network round trip time in milliseconds.
359e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_ROUND_TRIP_TIME = 0x3,
3604ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // The maximum number of simultaneous live streams in each direction.
361e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_MAX_CONCURRENT_STREAMS = 0x4,
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TCP congestion window in packets.
363e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_CURRENT_CWND = 0x5,
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Downstream byte retransmission rate in percentage.
365e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_DOWNLOAD_RETRANS_RATE = 0x6,
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initial window size in bytes
367e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_INITIAL_WINDOW_SIZE = 0x7,
3684ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // HPACK header table maximum size.
369e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_HEADER_TABLE_SIZE = 0x8,
3704ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Whether or not server push (PUSH_PROMISE) is enabled.
371e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  SETTINGS_ENABLE_PUSH = 0x9,
37203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // The size of the largest frame payload that a receiver is willing to accept.
37303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  SETTINGS_MAX_FRAME_SIZE = 0xa,
37403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // The maximum size of header list that the sender is prepared to accept.
37503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  SETTINGS_MAX_HEADER_LIST_SIZE = 0xb,
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Status codes for RST_STREAM frames.
3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)enum SpdyRstStreamStatus {
3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_INVALID = 0,
3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_PROTOCOL_ERROR = 1,
3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_INVALID_STREAM = 2,
3835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  RST_STREAM_STREAM_CLOSED = 2,  // Equivalent to INVALID_STREAM
3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_REFUSED_STREAM = 3,
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_UNSUPPORTED_VERSION = 4,
3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_CANCEL = 5,
3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_INTERNAL_ERROR = 6,
3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_FLOW_CONTROL_ERROR = 7,
3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_STREAM_IN_USE = 8,
3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_STREAM_ALREADY_CLOSED = 9,
3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_INVALID_CREDENTIALS = 10,
3925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // FRAME_TOO_LARGE (defined by SPDY versions 3.1 and below), and
3935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // FRAME_SIZE_ERROR (defined by HTTP/2) are mapped to the same internal
3945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // reset status.
3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RST_STREAM_FRAME_TOO_LARGE = 11,
3965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  RST_STREAM_FRAME_SIZE_ERROR = 11,
3975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  RST_STREAM_SETTINGS_TIMEOUT = 12,
3985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  RST_STREAM_CONNECT_ERROR = 13,
3995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  RST_STREAM_ENHANCE_YOUR_CALM = 14,
4005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  RST_STREAM_NUM_STATUS_CODES = 15
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Status codes for GOAWAY frames.
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum SpdyGoAwayStatus {
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GOAWAY_OK = 0,
4065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_NO_ERROR = GOAWAY_OK,
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GOAWAY_PROTOCOL_ERROR = 1,
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GOAWAY_INTERNAL_ERROR = 2,
4095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_FLOW_CONTROL_ERROR = 3,
4105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_SETTINGS_TIMEOUT = 4,
4115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_STREAM_CLOSED = 5,
4125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_FRAME_SIZE_ERROR = 6,
4135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_REFUSED_STREAM = 7,
4145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_CANCEL = 8,
4155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_COMPRESSION_ERROR = 9,
4165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_CONNECT_ERROR = 10,
4175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_ENHANCE_YOUR_CALM = 11,
4185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  GOAWAY_INADEQUATE_SECURITY = 12
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A SPDY priority is a number between 0 and 7 (inclusive).
422a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// SPDY priority range is version-dependent. For SPDY 2 and below, priority is a
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// number between 0 and 3.
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef uint8 SpdyPriority;
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef std::map<std::string, std::string> SpdyNameValueBlock;
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef uint64 SpdyPingId;
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
430cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)typedef std::string SpdyProtocolId;
431cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
4324ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch// TODO(hkhalil): Add direct testing for this? It won't increase coverage any,
4334ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch// but is good to do anyway.
4344ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdochclass NET_EXPORT_PRIVATE SpdyConstants {
4354ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch public:
4364ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Returns true if a given on-the-wire enumeration of a frame type is valid
4374ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // for a given protocol version, false otherwise.
4384ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  static bool IsValidFrameType(SpdyMajorVersion version, int frame_type_field);
4394ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
4404ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Parses a frame type from an on-the-wire enumeration of a given protocol
4414ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // version.
4424ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Behavior is undefined for invalid frame type fields; consumers should first
4434ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // use IsValidFrameType() to verify validity of frame type fields.
4444ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  static SpdyFrameType ParseFrameType(SpdyMajorVersion version,
4454ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch                                      int frame_type_field);
4464ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
4474ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Serializes a given frame type to the on-the-wire enumeration value for the
4484ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // given protocol version.
4494ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Returns -1 on failure (I.E. Invalid frame type for the given version).
4504ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  static int SerializeFrameType(SpdyMajorVersion version,
4514ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch                                SpdyFrameType frame_type);
4524ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
453116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Returns the frame type for non-control (i.e. data) frames
454116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // in the given SPDY version.
455116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static int DataFrameType(SpdyMajorVersion version);
456116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
4574ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Returns true if a given on-the-wire enumeration of a setting id is valid
4584ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // for a given protocol version, false otherwise.
4594ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  static bool IsValidSettingId(SpdyMajorVersion version, int setting_id_field);
4604ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
4614ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Parses a setting id from an on-the-wire enumeration of a given protocol
4624ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // version.
4634ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Behavior is undefined for invalid setting id fields; consumers should first
4644ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // use IsValidSettingId() to verify validity of setting id fields.
4654ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  static SpdySettingsIds ParseSettingId(SpdyMajorVersion version,
4664ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch                                        int setting_id_field);
4674ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
4684ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Serializes a given setting id to the on-the-wire enumeration value for the
4694ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // given protocol version.
4704ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // Returns -1 on failure (I.E. Invalid setting id for the given version).
4714ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  static int SerializeSettingId(SpdyMajorVersion version, SpdySettingsIds id);
4725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
4735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Returns true if a given on-the-wire enumeration of a RST_STREAM status code
4745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // is valid for a given protocol version, false otherwise.
4755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static bool IsValidRstStreamStatus(SpdyMajorVersion version,
4765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                                     int rst_stream_status_field);
4775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
4785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Parses a RST_STREAM status code from an on-the-wire enumeration of a given
4795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // protocol version.
4805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Behavior is undefined for invalid RST_STREAM status code fields; consumers
4815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM
4825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // status code fields..
4835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static SpdyRstStreamStatus ParseRstStreamStatus(SpdyMajorVersion version,
4845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                                                  int rst_stream_status_field);
4855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
4865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Serializes a given RST_STREAM status code to the on-the-wire enumeration
4875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // value for the given protocol version.
4885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given
4895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // version).
4905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static int SerializeRstStreamStatus(SpdyMajorVersion version,
4915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                                      SpdyRstStreamStatus rst_stream_status);
4925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
4935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Returns true if a given on-the-wire enumeration of a GOAWAY status code is
4945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // valid for the given protocol version, false otherwise.
4955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static bool IsValidGoAwayStatus(SpdyMajorVersion version,
4965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                                  int goaway_status_field);
4975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
4985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Parses a GOAWAY status from an on-the-wire enumeration of a given protocol
4995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // version.
5005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Behavior is undefined for invalid GOAWAY status fields; consumers should
5015c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields.
5025c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static SpdyGoAwayStatus ParseGoAwayStatus(SpdyMajorVersion version,
5035c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                                            int goaway_status_field);
5045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
5055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Serializes a given GOAWAY status to the on-the-wire enumeration value for
5065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // the given protocol version.
5075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version).
5085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static int SerializeGoAwayStatus(SpdyMajorVersion version,
5095c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                                   SpdyGoAwayStatus status);
5105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
5115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Size, in bytes, of the data frame header. Future versions of SPDY
5125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // will likely vary this, so we allow for the flexibility of a function call
5135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // for this value as opposed to a constant.
51403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  static size_t GetDataFrameMinimumSize(SpdyMajorVersion version);
5155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
5165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Size, in bytes, of the control frame header.
5175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static size_t GetControlFrameHeaderSize(SpdyMajorVersion version);
5185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
5195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static size_t GetPrefixLength(SpdyFrameType type, SpdyMajorVersion version);
5205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
5215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static size_t GetFrameMaximumSize(SpdyMajorVersion version);
5225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
523cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns the size of a header block size field. Valid only for SPDY
524cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // versions <= 3.
525cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  static size_t GetSizeOfSizeField(SpdyMajorVersion version);
526cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
527116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Returns the size (in bytes) of a wire setting ID and value.
528116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static size_t GetSettingSize(SpdyMajorVersion version);
529116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
5305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static SpdyMajorVersion ParseMajorVersion(int version_number);
5315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
5325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static int SerializeMajorVersion(SpdyMajorVersion version);
5335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
5345c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  static std::string GetVersionString(SpdyMajorVersion version);
5354ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch};
5364ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
5372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SpdyFrame;
5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef SpdyFrame SpdySerializedFrame;
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
540eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass SpdyFrameVisitor;
5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Intermediate representation for SPDY frames.
5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is
5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// gone.
5455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyFrameIR {
5462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
5472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~SpdyFrameIR() {}
5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
549eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const = 0;
550eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
5512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyFrameIR() {}
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyFrameIR);
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Abstract class intended to be inherited by IRs that have a stream associated
5592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// to them.
5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyFrameWithStreamIdIR : public SpdyFrameIR {
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~SpdyFrameWithStreamIdIR() {}
5632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyStreamId stream_id() const { return stream_id_; }
5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_stream_id(SpdyStreamId stream_id) {
5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DCHECK_EQ(0u, stream_id & ~kStreamIdMask);
5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    stream_id_ = stream_id;
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit SpdyFrameWithStreamIdIR(SpdyStreamId stream_id) {
5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    set_stream_id(stream_id);
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyStreamId stream_id_;
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithStreamIdIR);
5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Abstract class intended to be inherited by IRs that have the option of a FIN
5812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// flag. Implies SpdyFrameWithStreamIdIR.
5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyFrameWithFinIR : public SpdyFrameWithStreamIdIR {
5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~SpdyFrameWithFinIR() {}
5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool fin() const { return fin_; }
5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_fin(bool fin) { fin_ = fin; }
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit SpdyFrameWithFinIR(SpdyStreamId stream_id)
5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : SpdyFrameWithStreamIdIR(stream_id),
5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        fin_(false) {}
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool fin_;
5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithFinIR);
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Abstract class intended to be inherited by IRs that contain a name-value
6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// block. Implies SpdyFrameWithFinIR.
6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NET_EXPORT_PRIVATE SpdyFrameWithNameValueBlockIR
6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) {
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const SpdyNameValueBlock& name_value_block() const {
6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return name_value_block_;
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void set_name_value_block(const SpdyNameValueBlock& name_value_block) {
6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Deep copy.
6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    name_value_block_ = name_value_block;
6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetHeader(const base::StringPiece& name,
6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                 const base::StringPiece& value) {
6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    name_value_block_[name.as_string()] = value.as_string();
6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
615c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  SpdyNameValueBlock* mutable_name_value_block() {
616c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    return &name_value_block_;
617c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  }
6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit SpdyFrameWithNameValueBlockIR(SpdyStreamId stream_id);
6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~SpdyFrameWithNameValueBlockIR();
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyNameValueBlock name_value_block_;
6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyFrameWithNameValueBlockIR);
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NET_EXPORT_PRIVATE SpdyDataIR
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : public NON_EXPORTED_BASE(SpdyFrameWithFinIR) {
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Performs deep copy on data.
6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data);
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Use in conjunction with SetDataShallow() for shallow-copy on data.
6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit SpdyDataIR(SpdyStreamId stream_id);
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~SpdyDataIR();
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::StringPiece data() const { return data_; }
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
642116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool padded() const { return padded_; }
6434ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
6444ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  int padding_payload_len() const { return padding_payload_len_; }
6454ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
6464ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  void set_padding_len(int padding_len) {
6474ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch    DCHECK_GT(padding_len, 0);
648116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    DCHECK_LE(padding_len, kPaddingSizePerFrame);
649116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    padded_ = true;
650116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    // The pad field takes one octet on the wire.
651116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    padding_payload_len_ = padding_len - 1;
6524ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  }
6534ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Deep-copy of data (keep private copy).
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetDataDeep(const base::StringPiece& data) {
6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    data_store_.reset(new std::string(data.data(), data.length()));
6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    data_ = *(data_store_.get());
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Shallow-copy of data (do not keep private copy).
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetDataShallow(const base::StringPiece& data) {
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    data_store_.reset();
6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    data_ = data;
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
666eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
667eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Used to store data that this SpdyDataIR should own.
6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<std::string> data_store_;
6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::StringPiece data_;
6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
673116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool padded_;
6744ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  // padding_payload_len_ = desired padding length - len(padding length field).
6754ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch  int padding_payload_len_;
6764ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch
6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyDataIR);
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
680eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass NET_EXPORT_PRIVATE SpdySynStreamIR
681eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    : public SpdyFrameWithNameValueBlockIR {
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit SpdySynStreamIR(SpdyStreamId stream_id)
6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : SpdyFrameWithNameValueBlockIR(stream_id),
6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        associated_to_stream_id_(0),
6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        priority_(0),
6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        unidirectional_(false) {}
6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyStreamId associated_to_stream_id() const {
6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return associated_to_stream_id_;
6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_associated_to_stream_id(SpdyStreamId stream_id) {
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    associated_to_stream_id_ = stream_id;
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyPriority priority() const { return priority_; }
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_priority(SpdyPriority priority) { priority_ = priority; }
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool unidirectional() const { return unidirectional_; }
6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_unidirectional(bool unidirectional) {
6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    unidirectional_ = unidirectional;
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
701eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
702eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyStreamId associated_to_stream_id_;
7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyPriority priority_;
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool unidirectional_;
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdySynStreamIR);
7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdySynReplyIR : public SpdyFrameWithNameValueBlockIR {
7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
7132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit SpdySynReplyIR(SpdyStreamId stream_id)
7142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : SpdyFrameWithNameValueBlockIR(stream_id) {}
7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
716eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
717eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
7192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdySynReplyIR);
7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyRstStreamIR : public SpdyFrameWithStreamIdIR {
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SpdyRstStreamIR(SpdyStreamId stream_id, SpdyRstStreamStatus status,
7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  base::StringPiece description);
7265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~SpdyRstStreamIR();
7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyRstStreamStatus status() const {
7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return status_;
7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_status(SpdyRstStreamStatus status) {
7332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    status_ = status;
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::StringPiece description() const { return description_; }
7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void set_description(base::StringPiece description) {
7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    description_ = description;
7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
742eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
743eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyRstStreamStatus status_;
7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::StringPiece description_;
7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyRstStreamIR);
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR {
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
7532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Associates flags with a value.
7542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  struct Value {
7552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Value() : persist_value(false),
7562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              persisted(false),
7572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              value(0) {}
7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    bool persist_value;
7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    bool persisted;
7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    int32 value;
7612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
7622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  typedef std::map<SpdySettingsIds, Value> ValueMap;
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdySettingsIR();
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~SpdySettingsIR();
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Overwrites as appropriate.
7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const ValueMap& values() const { return values_; }
7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void AddSetting(SpdySettingsIds id,
7712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  bool persist_value,
7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  bool persisted,
7732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  int32 value) {
7742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    values_[id].persist_value = persist_value;
7752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    values_[id].persisted = persisted;
7762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    values_[id].value = value;
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
778a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool clear_settings() const { return clear_settings_; }
7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_clear_settings(bool clear_settings) {
7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    clear_settings_ = clear_settings;
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
783a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool is_ack() const { return is_ack_; }
784a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void set_is_ack(bool is_ack) {
785a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    is_ack_ = is_ack;
786a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
788eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
789eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ValueMap values_;
7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool clear_settings_;
793a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool is_ack_;
7942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdySettingsIR);
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyPingIR : public SpdyFrameIR {
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
800a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  explicit SpdyPingIR(SpdyPingId id) : id_(id), is_ack_(false) {}
8012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyPingId id() const { return id_; }
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
803a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // ACK logic is valid only for SPDY versions 4 and above.
804a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool is_ack() const { return is_ack_; }
805a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void set_is_ack(bool is_ack) { is_ack_ = is_ack; }
806a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
807eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
808eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
8102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyPingId id_;
811a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool is_ack_;
8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyPingIR);
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyGoAwayIR : public SpdyFrameIR {
8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SpdyGoAwayIR(SpdyStreamId last_good_stream_id, SpdyGoAwayStatus status,
8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)               const base::StringPiece& description);
8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~SpdyGoAwayIR();
8212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyStreamId last_good_stream_id() const { return last_good_stream_id_; }
8222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_last_good_stream_id(SpdyStreamId last_good_stream_id) {
8232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DCHECK_LE(0u, last_good_stream_id);
8242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DCHECK_EQ(0u, last_good_stream_id & ~kStreamIdMask);
8252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    last_good_stream_id_ = last_good_stream_id;
8262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
8272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyGoAwayStatus status() const { return status_; }
8282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_status(SpdyGoAwayStatus status) {
8292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // TODO(hkhalil): Check valid ranges of status?
8302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    status_ = status;
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::StringPiece& description() const;
8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
835eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
836eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
8382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyStreamId last_good_stream_id_;
8392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyGoAwayStatus status_;
8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::StringPiece description_;
8412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyGoAwayIR);
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithNameValueBlockIR {
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
8472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit SpdyHeadersIR(SpdyStreamId stream_id)
848a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    : SpdyFrameWithNameValueBlockIR(stream_id),
849a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      has_priority_(false),
850a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      priority_(0) {}
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
852eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
853eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
854a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool has_priority() const { return has_priority_; }
855a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void set_has_priority(bool has_priority) { has_priority_ = has_priority; }
856a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  uint32 priority() const { return priority_; }
857a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void set_priority(SpdyPriority priority) { priority_ = priority; }
858a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
860a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool has_priority_;
861a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // 31-bit priority.
862a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  uint32 priority_;
8632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyHeadersIR);
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyWindowUpdateIR : public SpdyFrameWithStreamIdIR {
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SpdyWindowUpdateIR(SpdyStreamId stream_id, int32 delta)
8692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      : SpdyFrameWithStreamIdIR(stream_id) {
8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    set_delta(delta);
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int32 delta() const { return delta_; }
8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_delta(int32 delta) {
8742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DCHECK_LT(0, delta);
8752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DCHECK_LE(delta, kSpdyMaximumWindowSize);
8762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    delta_ = delta;
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
879eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
880eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int32 delta_;
8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateIR);
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
887eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass NET_EXPORT_PRIVATE SpdyBlockedIR
888eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    : public NON_EXPORTED_BASE(SpdyFrameWithStreamIdIR) {
8895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
8905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit SpdyBlockedIR(SpdyStreamId stream_id)
8915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : SpdyFrameWithStreamIdIR(stream_id) {}
892868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
893eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
894eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
8955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
8965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyBlockedIR);
897868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
898868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
8995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyPushPromiseIR
9005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : public SpdyFrameWithNameValueBlockIR {
9017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public:
9027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SpdyPushPromiseIR(SpdyStreamId stream_id, SpdyStreamId promised_stream_id)
9037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      : SpdyFrameWithNameValueBlockIR(stream_id),
904cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        promised_stream_id_(promised_stream_id) {}
9057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SpdyStreamId promised_stream_id() const { return promised_stream_id_; }
9067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void set_promised_stream_id(SpdyStreamId id) { promised_stream_id_ = id; }
9077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
9087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
9097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
9107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch private:
9117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  SpdyStreamId promised_stream_id_;
9127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  DISALLOW_COPY_AND_ASSIGN(SpdyPushPromiseIR);
9137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch};
9147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
91523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// TODO(jgraettinger): This representation needs review. SpdyContinuationIR
91623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// needs to frame a portion of a single, arbitrarily-broken encoded buffer.
917a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyContinuationIR
918a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    : public SpdyFrameWithNameValueBlockIR {
919a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
920a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  explicit SpdyContinuationIR(SpdyStreamId stream_id)
921a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      : SpdyFrameWithNameValueBlockIR(stream_id),
922a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        end_headers_(false) {}
923a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
924a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
925a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
926a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool end_headers() const { return end_headers_; }
927a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void set_end_headers(bool end_headers) {end_headers_ = end_headers;}
928a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
929a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
930a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool end_headers_;
931a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyContinuationIR);
932a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
9337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
934cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class NET_EXPORT_PRIVATE SpdyAltSvcIR : public SpdyFrameWithStreamIdIR {
935cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public:
936cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  explicit SpdyAltSvcIR(SpdyStreamId stream_id);
937cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
938cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  uint32 max_age() const { return max_age_; }
939cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  uint16 port() const { return port_; }
940cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  SpdyProtocolId protocol_id() const {
941cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return protocol_id_;
942cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
943cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  std::string host() const { return host_; }
944cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  std::string origin() const { return origin_; }
945cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
946cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void set_max_age(uint32 max_age) { max_age_ = max_age; }
947cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void set_port(uint16 port) { port_ = port; }
948cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void set_protocol_id(SpdyProtocolId protocol_id) {
949cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    protocol_id_ = protocol_id;
950cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
951cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void set_host(std::string host) {
952cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    host_ = host;
953cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
954cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void set_origin(std::string origin) {
955cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    origin_ = origin;
956cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
957cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
958cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE;
959cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
960cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) private:
961cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  uint32 max_age_;
962cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  uint16 port_;
963cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  SpdyProtocolId protocol_id_;
964cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  std::string host_;
965cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  std::string origin_;
966cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SpdyAltSvcIR);
967cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)};
968cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
969116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR {
970116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public:
971116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  explicit SpdyPriorityIR(SpdyStreamId stream_id);
972