proxygen
HTTPCommonHeadersTests.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
12 
13 using namespace proxygen;
14 
16 };
17 
19  std::string common1("Content-Length");
20  std::string common2("content-length");
21  std::string uncommon("Uncommon");
22 
23  HTTPHeaderCode commonCode1 = HTTPCommonHeaders::hash(common1);
24  HTTPHeaderCode commonCode2 = HTTPCommonHeaders::hash(common2);
25  HTTPHeaderCode uncommonCode = HTTPCommonHeaders::hash(uncommon);
26 
29 
30  EXPECT_EQ(commonCode1, commonCode2);
31 }
32 
33 TEST_F(HTTPCommonHeadersTests, TestTwoTablesInitialized) {
34  std::string common("Content-Length");
36 
37  EXPECT_EQ(*HTTPCommonHeaders::getPointerToHeaderName(code), "Content-Length");
38  EXPECT_EQ(
40  code, HTTPCommonHeaderTableType::TABLE_LOWERCASE), "content-length");
41 }
42 
43 TEST_F(HTTPCommonHeadersTests, TestIsCommonHeaderNameFromTable) {
44  // The first two hardcoded headers are not considered actual common headers
53 
54  // Verify that the first actual common header in the address table checks out
55  // Assuming there is at least one common header in the table (first two
56  // entries are HTTP_HEADER_NONE and HTTP_HEADER_OTHER)
61  static_cast<HTTPHeaderCode>(HTTPHeaderCodeCommonOffset + 1)),
63 
64  // Verify that the last header in the common address table checks out
68  static_cast<HTTPHeaderCode>(
70  }
71 
72  // Verify that a random header is not identified as being part of the common
73  // address table
74  std::string externalHeader = "externalHeader";
76  &externalHeader, TABLE_CAMELCASE));
77 }
78 
79 TEST_F(HTTPCommonHeadersTests, TestGetHeaderCodeFromTableCommonHeaderName) {
82  HTTPHeaderCode code = static_cast<HTTPHeaderCode>(j);
84  code ==
87  }
88  std::string externalHeader = "externalHeader";
91  &externalHeader, TABLE_CAMELCASE));
92 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static HTTPHeaderCode getHeaderCodeFromTableCommonHeaderName(const std::string *headerName, HTTPCommonHeaderTableType type)
static bool isHeaderNameFromTable(const std::string *headerName, HTTPCommonHeaderTableType type)
static const std::string * getPointerToHeaderName(HTTPHeaderCode code, HTTPCommonHeaderTableType type=TABLE_CAMELCASE)
Definition: common.py:1
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
static constexpr uint64_t num_header_codes
const char * string
Definition: Conv.cpp:212
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
const uint8_t HTTPHeaderCodeCommonOffset
TEST_F(HeaderTableTests, IndexTranslation)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
static FB_EXPORT HTTPHeaderCode hash(const char *name, size_t len)