proxygen
HTTPMethod.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  */
11 
13 #include <folly/Indestructible.h>
15 #include <vector>
16 
17 #define HTTP_METHOD_STR(method) #method
18 
19 namespace {
20 
21 // Method strings. This is indestructible because this structure is
22 // accessed from multiple threads and still needs to be accessible after exit()
23 // is called to avoid crashing.
24 using StringVector = std::vector<std::string>;
25 
26 const StringVector& getMethodStrings() {
27  static const folly::Indestructible<StringVector> methodStrings{
29  };
30  return *methodStrings;
31 }
32 
33 }
34 
35 namespace proxygen {
36 
38  FOR_EACH_ENUMERATE(index, cur, getMethodStrings()) {
39  if (caseInsensitiveEqual(*cur, method)) {
40  return HTTPMethod(index);
41  }
42  }
43  return folly::none;
44 }
45 
47  return getMethodStrings()[static_cast<unsigned>(method)];
48 }
49 
50 std::ostream& operator <<(std::ostream& out, HTTPMethod method) {
51  out << methodToString(method);
52  return out;
53 }
54 
55 }
folly::Optional< HTTPMethod > stringToMethod(folly::StringPiece method)
Definition: HTTPMethod.cpp:37
bool caseInsensitiveEqual(folly::StringPiece s, folly::StringPiece t)
Definition: UtilInl.h:17
std::ostream & operator<<(std::ostream &os, const HeaderTable &table)
#define HTTP_METHOD_STR(method)
Definition: HTTPMethod.cpp:17
vector< std::string > StringVector
#define HTTP_METHOD_GEN(x)
Definition: HTTPMethod.h:19
const std::string & methodToString(HTTPMethod method)
Definition: HTTPMethod.cpp:46
#define FOR_EACH_ENUMERATE(count, i, c)
Definition: Foreach.h:170
const char * string
Definition: Conv.cpp:212
constexpr None none
Definition: Optional.h:87