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 QUICHE_SPDY_CORE_HPACK_HPACK_CONSTANTS_H_ 6 #define QUICHE_SPDY_CORE_HPACK_HPACK_CONSTANTS_H_ 7 8 #include <cstddef> 9 #include <cstdint> 10 #include <vector> 11 12 #include "quiche/common/platform/api/quiche_export.h" 13 14 // All section references below are to 15 // https://httpwg.org/specs/rfc7540.html and 16 // https://httpwg.org/specs/rfc7541.html. 17 18 namespace spdy { 19 20 // An HpackPrefix signifies |bits| stored in the top |bit_size| bits 21 // of an octet. 22 struct QUICHE_EXPORT HpackPrefix { 23 uint8_t bits; 24 size_t bit_size; 25 }; 26 27 // Represents a symbol and its Huffman code (stored in most-significant bits). 28 struct QUICHE_EXPORT HpackHuffmanSymbol { 29 uint32_t code; 30 uint8_t length; 31 uint16_t id; 32 }; 33 34 // An entry in the static table. Must be a POD in order to avoid static 35 // initializers, i.e. no user-defined constructors or destructors. 36 struct QUICHE_EXPORT HpackStaticEntry { 37 const char* const name; 38 const size_t name_len; 39 const char* const value; 40 const size_t value_len; 41 }; 42 43 class HpackStaticTable; 44 45 // RFC 7540, 6.5.2: Initial value for SETTINGS_HEADER_TABLE_SIZE. 46 inline constexpr uint32_t kDefaultHeaderTableSizeSetting = 4096; 47 48 // RFC 7541, 5.2: Flag for a string literal that is stored unmodified (i.e., 49 // without Huffman encoding). 50 inline constexpr HpackPrefix kStringLiteralIdentityEncoded = {0x0, 1}; 51 52 // RFC 7541, 5.2: Flag for a Huffman-coded string literal. 53 inline constexpr HpackPrefix kStringLiteralHuffmanEncoded = {0x1, 1}; 54 55 // RFC 7541, 6.1: Opcode for an indexed header field. 56 inline constexpr HpackPrefix kIndexedOpcode = {0b1, 1}; 57 58 // RFC 7541, 6.2.1: Opcode for a literal header field with incremental indexing. 59 inline constexpr HpackPrefix kLiteralIncrementalIndexOpcode = {0b01, 2}; 60 61 // RFC 7541, 6.2.2: Opcode for a literal header field without indexing. 62 inline constexpr HpackPrefix kLiteralNoIndexOpcode = {0b0000, 4}; 63 64 // RFC 7541, 6.2.3: Opcode for a literal header field which is never indexed. 65 // Currently unused. 66 // const HpackPrefix kLiteralNeverIndexOpcode = {0b0001, 4}; 67 68 // RFC 7541, 6.3: Opcode for maximum header table size update. Begins a 69 // varint-encoded table size with a 5-bit prefix. 70 inline constexpr HpackPrefix kHeaderTableSizeUpdateOpcode = {0b001, 3}; 71 72 // RFC 7541, Appendix B: Huffman Code. 73 QUICHE_EXPORT const std::vector<HpackHuffmanSymbol>& HpackHuffmanCodeVector(); 74 75 // RFC 7541, Appendix A: Static Table Definition. 76 QUICHE_EXPORT const std::vector<HpackStaticEntry>& HpackStaticTableVector(); 77 78 // Returns a HpackStaticTable instance initialized with |kHpackStaticTable|. 79 // The instance is read-only, has static lifetime, and is safe to share amoung 80 // threads. This function is thread-safe. 81 QUICHE_EXPORT const HpackStaticTable& ObtainHpackStaticTable(); 82 83 // RFC 7541, 8.1.2.1: Pseudo-headers start with a colon. 84 inline constexpr char kPseudoHeaderPrefix = ':'; 85 86 } // namespace spdy 87 88 #endif // QUICHE_SPDY_CORE_HPACK_HPACK_CONSTANTS_H_ 89