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 {
76 };
77 
78 NET_API UT_StringHolder NETknownHeadersToString(NET_KnownHeaders header);
79 
80 namespace NET
81 {
82 enum class HTTPError
83 {
84  INTERNAL_ERROR = -1,
85  OK = 0,
87 };
88 
90 
91 inline UT_ErrorCode
93 {
94  return UT_ErrorCode{static_cast<int>(e), GetHTTPErrorCategory()};
95 }
96 }; // namespace NET
97 
98 namespace std
99 {
100 template <>
101 struct is_error_code_enum<NET::HTTPError> : true_type
102 {
103 };
104 } // namespace std
105 
106 #endif // __NET_WEBTYPES_H__
107 
std::pair< int64, int64 > NET_RequestRange
Definition: NET_WebTypes.h:50
unsigned hash() const
Unsorted map container.
Definition: UT_Map.h:107
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:82
NET_API UT_StringHolder NETknownHeadersToString(NET_KnownHeaders header)
NET_HTTPMethod
Definition: NET_WebTypes.h:53