QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 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 "net/third_party/quiche/src/spdy/platform/api/spdy_export.h" |
| 13 | |
| 14 | // All section references below are to |
bnc | a4aaf75 | 2019-02-22 16:59:35 -0800 | [diff] [blame] | 15 | // https://httpwg.org/specs/rfc7540.html and |
| 16 | // https://httpwg.org/specs/rfc7541.html. |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 17 | |
| 18 | namespace spdy { |
| 19 | |
| 20 | // An HpackPrefix signifies |bits| stored in the top |bit_size| bits |
| 21 | // of an octet. |
| 22 | struct 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 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 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 HpackHuffmanTable; |
| 44 | class HpackStaticTable; |
| 45 | |
bnc | a4aaf75 | 2019-02-22 16:59:35 -0800 | [diff] [blame] | 46 | // RFC 7540, 6.5.2: Initial value for SETTINGS_HEADER_TABLE_SIZE. |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 47 | const uint32_t kDefaultHeaderTableSizeSetting = 4096; |
| 48 | |
| 49 | // RFC 7541, 5.2: Flag for a string literal that is stored unmodified (i.e., |
| 50 | // without Huffman encoding). |
| 51 | const HpackPrefix kStringLiteralIdentityEncoded = {0x0, 1}; |
| 52 | |
| 53 | // RFC 7541, 5.2: Flag for a Huffman-coded string literal. |
| 54 | const HpackPrefix kStringLiteralHuffmanEncoded = {0x1, 1}; |
| 55 | |
| 56 | // RFC 7541, 6.1: Opcode for an indexed header field. |
| 57 | const HpackPrefix kIndexedOpcode = {0b1, 1}; |
| 58 | |
| 59 | // RFC 7541, 6.2.1: Opcode for a literal header field with incremental indexing. |
| 60 | const HpackPrefix kLiteralIncrementalIndexOpcode = {0b01, 2}; |
| 61 | |
| 62 | // RFC 7541, 6.2.2: Opcode for a literal header field without indexing. |
| 63 | const HpackPrefix kLiteralNoIndexOpcode = {0b0000, 4}; |
| 64 | |
| 65 | // RFC 7541, 6.2.3: Opcode for a literal header field which is never indexed. |
| 66 | // Currently unused. |
| 67 | // const HpackPrefix kLiteralNeverIndexOpcode = {0b0001, 4}; |
| 68 | |
| 69 | // RFC 7541, 6.3: Opcode for maximum header table size update. Begins a |
| 70 | // varint-encoded table size with a 5-bit prefix. |
| 71 | const HpackPrefix kHeaderTableSizeUpdateOpcode = {0b001, 3}; |
| 72 | |
bnc | a4aaf75 | 2019-02-22 16:59:35 -0800 | [diff] [blame] | 73 | // RFC 7541, Appendix B: Huffman Code. |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 74 | SPDY_EXPORT_PRIVATE const std::vector<HpackHuffmanSymbol>& |
| 75 | HpackHuffmanCodeVector(); |
| 76 | |
bnc | a4aaf75 | 2019-02-22 16:59:35 -0800 | [diff] [blame] | 77 | // RFC 7541, Appendix A: Static Table Definition. |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 78 | SPDY_EXPORT_PRIVATE const std::vector<HpackStaticEntry>& |
| 79 | HpackStaticTableVector(); |
| 80 | |
| 81 | // Returns a HpackHuffmanTable instance initialized with |kHpackHuffmanCode|. |
| 82 | // The instance is read-only, has static lifetime, and is safe to share amoung |
| 83 | // threads. This function is thread-safe. |
| 84 | SPDY_EXPORT_PRIVATE const HpackHuffmanTable& ObtainHpackHuffmanTable(); |
| 85 | |
| 86 | // Returns a HpackStaticTable instance initialized with |kHpackStaticTable|. |
| 87 | // The instance is read-only, has static lifetime, and is safe to share amoung |
| 88 | // threads. This function is thread-safe. |
| 89 | SPDY_EXPORT_PRIVATE const HpackStaticTable& ObtainHpackStaticTable(); |
| 90 | |
bnc | a4aaf75 | 2019-02-22 16:59:35 -0800 | [diff] [blame] | 91 | // RFC 7541, 8.1.2.1: Pseudo-headers start with a colon. |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 92 | const char kPseudoHeaderPrefix = ':'; |
| 93 | |
| 94 | } // namespace spdy |
| 95 | |
| 96 | #endif // QUICHE_SPDY_CORE_HPACK_HPACK_CONSTANTS_H_ |