hpack_constants.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef NET_SPDY_HPACK_CONSTANTS_H_ 6#define NET_SPDY_HPACK_CONSTANTS_H_ 7 8#include <vector> 9 10#include "base/basictypes.h" 11#include "net/base/net_export.h" 12 13// All section references below are to 14// http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 15 16namespace net { 17 18// An HpackPrefix signifies |bits| stored in the top |bit_size| bits 19// of an octet. 20struct HpackPrefix { 21 uint8 bits; 22 size_t bit_size; 23}; 24 25// Represents a symbol and its Huffman code (stored in most-significant bits). 26struct HpackHuffmanSymbol { 27 uint32 code; 28 uint8 length; 29 uint16 id; 30}; 31 32class HpackHuffmanTable; 33 34const uint32 kDefaultHeaderTableSizeSetting = 4096; 35 36// Largest string literal an HpackDecoder/HpackEncoder will attempt to process 37// before returning an error. 38const uint32 kDefaultMaxStringLiteralSize = 16 * 1024; 39 40// Maximum amount of encoded header buffer HpackDecoder will retain before 41// returning an error. 42// TODO(jgraettinger): Remove with SpdyHeadersHandlerInterface switch. 43const uint32 kMaxDecodeBufferSize = 32 * 1024; 44 45// 6.2: Flag for a string literal that is stored unmodified (i.e., 46// without Huffman encoding). 47const HpackPrefix kStringLiteralIdentityEncoded = { 0x0, 1 }; 48 49// 6.2: Flag for a Huffman-coded string literal. 50const HpackPrefix kStringLiteralHuffmanEncoded = { 0x1, 1 }; 51 52// 7.1: Opcode for an indexed header field. 53const HpackPrefix kIndexedOpcode = { 0x1, 1 }; 54 55// 7.2.1: Opcode for a literal header field with incremental indexing. 56const HpackPrefix kLiteralIncrementalIndexOpcode = { 0x1, 2 }; 57 58// 7.2.2: Opcode for a literal header field without indexing. 59const HpackPrefix kLiteralNoIndexOpcode = { 0x0, 4 }; 60 61// 7.2.3: Opcode for a literal header field which is never indexed. 62const HpackPrefix kLiteralNeverIndexOpcode = { 0x1, 4 }; 63 64// 7.3: Opcode for maximum header table size update. Begins a varint-encoded 65// table size with a 5-bit prefix. 66const HpackPrefix kHeaderTableSizeUpdateOpcode = { 0x1, 3 }; 67 68// Returns symbol code table from "Appendix C. Huffman Codes". 69NET_EXPORT_PRIVATE std::vector<HpackHuffmanSymbol> HpackHuffmanCode(); 70 71// Returns a HpackHuffmanTable instance initialized with |kHpackHuffmanCode|. 72// The instance is read-only, has static lifetime, and is safe to share amoung 73// threads. This function is thread-safe. 74NET_EXPORT_PRIVATE const HpackHuffmanTable& ObtainHpackHuffmanTable(); 75 76} // namespace net 77 78#endif // NET_SPDY_HPACK_CONSTANTS_H_ 79