HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_WebTypes.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: NET_WebTypes.h
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __NET_WEBTYPES_H__
13 #define __NET_WEBTYPES_H__
14 
15 #include "NET_API.h"
16 
17 #include <UT/UT_ErrorCode.h>
18 #include <UT/UT_Map.h>
19 #include <UT/UT_StringHolder.h>
20 
21 #include <utility>
22 
23 /// We need a compare function that ignores case as it does not matter in the
24 /// world of http headers
26 {
27  bool operator()(const UT_StringHolder &lhs,
28  const UT_StringHolder &rhs) const
29  {
30  return lhs.equal(rhs, true /*ignore case*/);
31  }
32 };
33 
34 /// We need a custom hasher that doesnt take case into account.
36 {
37  size_t operator()(const UT_StringHolder &str) const
38  {
39  return str.toLower().hash();
40  }
41 };
42 
43 /// Use this when storing a map for web uses
45  UT_StringHolder,
48 
49 
50 using NET_RequestRange = std::pair<int64, int64>;
52 
53 enum class NET_HTTPMethod
54 {
55  kGET,
56  kHEAD,
57  kPOST,
58  kPUT,
59  kDELETE,
60  kCONNECT,
61  kOPTIONS,
62  kTRACE,
63  kPATCH
64 };
65 
67 {
77 };
78 
79 NET_API UT_StringHolder NETknownHeadersToString(NET_KnownHeaders header);
80 
81 namespace NET
82 {
83 enum class HTTPError
84 {
85  INTERNAL_ERROR = -1,
86  OK = 0,
88 };
89 
91 
92 inline UT_ErrorCode
94 {
95  return UT_ErrorCode{static_cast<int>(e), GetHTTPErrorCategory()};
96 }
97 }; // namespace NET
98 
99 namespace std
100 {
101 template <>
102 struct is_error_code_enum<NET::HTTPError> : true_type
103 {
104 };
105 } // namespace std
106 
107 #endif // __NET_WEBTYPES_H__
108 
std::pair< int64, int64 > NET_RequestRange
Definition: NET_WebTypes.h:50
unsigned hash() const
Unsorted map container.
Definition: UT_Map.h:109
bool equal(const UT_StringRef &str, bool ignore_case=false) const
std::error_category UT_ErrorCategory
Definition: UT_ErrorCode.h:22
UT_ErrorCode make_error_code(NET::CurlError e)
NET_API const UT_ErrorCategory & GetHTTPErrorCategory()
#define NET_API
Definition: NET_API.h:9
NET_KnownHeaders
Definition: NET_WebTypes.h:66
std::error_code UT_ErrorCode
Definition: UT_ErrorCode.h:20
bool operator()(const UT_StringHolder &lhs, const UT_StringHolder &rhs) const
Definition: NET_WebTypes.h:27
size_t operator()(const UT_StringHolder &str) const
Definition: NET_WebTypes.h:37
SYS_NO_DISCARD_RESULT UT_StringRef toLower() const
We need a custom hasher that doesnt take case into account.
Definition: NET_WebTypes.h:35
HTTPError
Definition: NET_WebTypes.h:83
NET_API UT_StringHolder NETknownHeadersToString(NET_KnownHeaders header)
NET_HTTPMethod
Definition: NET_WebTypes.h:53