blob: d3f9d8d80dd1d4608f3766cb79388eb90e492518 [file] [log] [blame]
QUICHE team82dee2f2019-01-18 12:35:12 -05001// 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
bnca4aaf752019-02-22 16:59:35 -080015// https://httpwg.org/specs/rfc7540.html and
16// https://httpwg.org/specs/rfc7541.html.
QUICHE team82dee2f2019-01-18 12:35:12 -050017
18namespace spdy {
19
20// An HpackPrefix signifies |bits| stored in the top |bit_size| bits
21// of an octet.
22struct 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).
28struct 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.
36struct 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
43class HpackHuffmanTable;
44class HpackStaticTable;
45
bnca4aaf752019-02-22 16:59:35 -080046// RFC 7540, 6.5.2: Initial value for SETTINGS_HEADER_TABLE_SIZE.
QUICHE team82dee2f2019-01-18 12:35:12 -050047const 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).
51const HpackPrefix kStringLiteralIdentityEncoded = {0x0, 1};
52
53// RFC 7541, 5.2: Flag for a Huffman-coded string literal.
54const HpackPrefix kStringLiteralHuffmanEncoded = {0x1, 1};
55
56// RFC 7541, 6.1: Opcode for an indexed header field.
57const HpackPrefix kIndexedOpcode = {0b1, 1};
58
59// RFC 7541, 6.2.1: Opcode for a literal header field with incremental indexing.
60const HpackPrefix kLiteralIncrementalIndexOpcode = {0b01, 2};
61
62// RFC 7541, 6.2.2: Opcode for a literal header field without indexing.
63const 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.
71const HpackPrefix kHeaderTableSizeUpdateOpcode = {0b001, 3};
72
bnca4aaf752019-02-22 16:59:35 -080073// RFC 7541, Appendix B: Huffman Code.
QUICHE team82dee2f2019-01-18 12:35:12 -050074SPDY_EXPORT_PRIVATE const std::vector<HpackHuffmanSymbol>&
75HpackHuffmanCodeVector();
76
bnca4aaf752019-02-22 16:59:35 -080077// RFC 7541, Appendix A: Static Table Definition.
QUICHE team82dee2f2019-01-18 12:35:12 -050078SPDY_EXPORT_PRIVATE const std::vector<HpackStaticEntry>&
79HpackStaticTableVector();
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.
84SPDY_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.
89SPDY_EXPORT_PRIVATE const HpackStaticTable& ObtainHpackStaticTable();
90
bnca4aaf752019-02-22 16:59:35 -080091// RFC 7541, 8.1.2.1: Pseudo-headers start with a colon.
QUICHE team82dee2f2019-01-18 12:35:12 -050092const char kPseudoHeaderPrefix = ':';
93
94} // namespace spdy
95
96#endif // QUICHE_SPDY_CORE_HPACK_HPACK_CONSTANTS_H_