1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
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.
7  */
8 
9 #pragma once
10 
11 #include <folly/Optional.h>
12 #include <folly/Range.h>
13 #include <string>
14 
15 namespace proxygen {
16 
17 /**
18  * Defined in winnt.h
19  * Several proxygen files include folly/portability/OpenSSL.h
20  *   -> folly/portability/Windows.h -> Windows.h -> winnt.h
21  */
22 #if defined(_WIN32) && defined(DELETE)
23 #undef DELETE
24 #endif
25 
26 /**
27  * See the definitions in RFC2616 5.1.1 for the source of this
28  * list. Today, proxygen only understands the methods defined in 5.1.1 and
29  * is not aware of any extension methods. If you wish to support extension
30  * methods, you must handle those separately from this enum.
31  */
32 enum class HTTPMethod {
33   GET,
34   POST,
35   OPTIONS,
36   DELETE,
37   HEAD,
38   CONNECT,
39   CONNECT_UDP,
40   PUT,
41   TRACE,
42   PATCH,
43   SUB,
44   PUB,
45   UNSUB
46 };
47 
48 /**
49  * Returns the HTTPMethod that matches the method. Although RFC2616 5.1.1
50  * says methods are case-sensitive, we ignore case here since most
51  * programmers probably really meant "GET" not "get". If the method is not
52  * recognized, the return value will be None
53  */
54 extern folly::Optional<HTTPMethod> stringToMethod(folly::StringPiece method);
55 
56 /**
57  * Returns a string representation of the method. If EXTENSION_METHOD is
58  * passed, then an empty string is returned
59  */
60 extern const std::string& methodToString(HTTPMethod method);
61 
62 std::ostream& operator<<(std::ostream& os, HTTPMethod method);
63 
64 } // namespace proxygen
65