• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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_BALSA_HEADER_PROPERTIES_H_
6 #define QUICHE_BALSA_HEADER_PROPERTIES_H_
7 
8 #include <cstdint>
9 
10 #include "absl/strings/string_view.h"
11 #include "quiche/common/platform/api/quiche_export.h"
12 
13 namespace quiche::header_properties {
14 
15 // Returns true if RFC 2616 Section 14 (or other relevant standards or
16 // practices) indicates that header can have multiple values. Note that nothing
17 // stops clients from sending multiple values of other headers, so this may not
18 // be perfectly reliable in practice.
19 QUICHE_EXPORT bool IsMultivaluedHeader(absl::string_view header);
20 
21 // An array of characters that are invalid in HTTP header field names.
22 // These are control characters, including \t, \n, \r, as well as space and
23 // (),/;<=>?@[\]{} and \x7f (see
24 // https://tools.ietf.org/html/rfc7230#section-3.2.6).
25 inline constexpr char kInvalidHeaderKeyCharList[] = {
26     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
27     0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
28     0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
29     0x1E, 0x1F, ' ',  '(',  ')',  ',',  '/',  ';',  '<',  '=',
30     '>',  '?',  '@',  '[',  '\\', ']',  '{',  '}',  0x7f};
31 
32 // An array of characters that are invalid in HTTP header field values,
33 // according to RFC 7230 Section 3.2.  Valid low characters not in this array
34 // are \t (0x09), \n (0x0A), and \r (0x0D).
35 // Note that HTTP header field names are even more restrictive.
36 inline constexpr char kInvalidHeaderCharList[] = {
37     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0B,
38     0x0C, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
39     0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x7F};
40 
41 // Returns true if the given `c` is invalid in a header field name.
42 QUICHE_EXPORT bool IsInvalidHeaderKeyChar(uint8_t c);
43 // Returns true if the given `c` is invalid in a header field or the `value` has
44 // invalid characters.
45 QUICHE_EXPORT bool IsInvalidHeaderChar(uint8_t c);
46 QUICHE_EXPORT bool HasInvalidHeaderChars(absl::string_view value);
47 
48 }  // namespace quiche::header_properties
49 
50 #endif  // QUICHE_BALSA_HEADER_PROPERTIES_H_
51