iFun Engine API  1.0.0-b6053
Great Technology for Great Games
http_util.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_NETWORK_HTTP_UTIL_H_
10 #define INCLUDE_FUNAPI_NETWORK_HTTP_UTIL_H_
11 
12 #include <boost/algorithm/string/predicate.hpp>
13 #include <funapi/types.h>
14 #include <funapi/utility/misc.h>
15 
16 #include <map>
17 
18 
19 namespace fun {
20 namespace http {
21 
23 typedef std::multimap<string, string, impl::util::CaseInsensitiveLess> Header;
24 
26 typedef std::map<string, string, impl::util::CaseInsensitiveLess> GetParameter;
27 
29 typedef std::map<string, std::vector<string>,
30  impl::util::CaseInsensitiveLess> GetParameter2;
31 
34 enum Method {
36  kGet,
39  kPut,
43 };
44 
45 
47 enum Version {
51 };
52 
53 
55 enum Protocol {
56  kHttp = 0,
58 };
59 
60 
63 enum StatusCode {
64  kContinue = 100,
65  kSwitchingProtocols = 101,
66  kOk = 200,
67  kCreated = 201,
68  kAccepted = 202,
69  kNonAuthoritativeInformation = 203,
70  kNoContent = 204,
71  kResetContent = 205,
72  kPartialContent = 206,
73  kMultipleChoices = 300,
74  kMovedPermanently = 301,
75  kFound = 302,
76  kSeeOther = 303,
77  kNotModified = 304,
78  kUseProxy = 305,
79  kTemporaryRedirect = 307,
80  kBadRequest = 400,
81  kUnauthorized = 401,
82  kPaymentRequired = 402,
83  kForbidden = 403,
84  kNotFound = 404,
85  kMethodNotAllowed = 405,
86  kNotAcceptable = 406,
87  kProxyAuthenticationRequired = 407,
88  kRequestTimeout = 408,
89  kConflict = 409,
90  kGone = 410,
91  kLengthRequired = 411,
92  kPreconditionFailed = 412,
93  kRequestEntityTooLarge = 413, // == Payload Too Large
94  kRequestUriTooLong = 414,
95  kUnsupportedMediaType = 415,
96  kRequestRangeNotSatisfiable = 416,
97  kExpectationFailed = 417,
98  kTooManyRequests = 429,
99  kInternalServerError = 500,
100  kNotImplemented = 501,
101  kBadGateway = 502,
102  kServiceUnavailable = 503,
103  kGatewayTimeout = 504,
104  kHttpVersionNotSupported = 505
105 };
106 
107 
109 struct FUNAPI_DLL_VISIBILITY Request {
111 
113  string request_ip;
114  string request_uri;
116  GetParameter get_parameter;
117  Header header;
118  string body;
119 };
120 
121 
123 struct FUNAPI_DLL_VISIBILITY Request2 {
125 
127  string request_ip;
128  string request_uri;
130  GetParameter2 get_parameter;
131  Header header;
132  string body;
133 };
134 
135 
137 struct FUNAPI_DLL_VISIBILITY Response {
139 
141  uint32_t status_code;
142  string status_message;
143  Header header;
144  string body;
145 };
146 
147 
161 class FUNAPI_DLL_VISIBILITY Uri {
162  public:
163 
165  Uri();
166 
169  explicit Uri(const string &uri_string);
170 
172  Uri(const Uri &rhs);
173 
175  Uri &operator=(const Uri &rhs);
176 
179  bool Parse(const string &uri_string);
180 
183  const string &protocol() const;
184 
187  const string &host() const;
188 
191  uint16_t port() const;
192 
195  const string &path() const;
196 
199  const string &query_string() const;
200 
203  const string &raw() const;
204 
205  private:
206  void Reset();
207 
208  string protocol_;
209  string host_;
210  uint16_t port_;
211  string path_;
212  string query_string_;
213  string url_string_;
214 };
215 
216 
220 FUNAPI_DLL_VISIBILITY const string &GetMethodString(const Method &method);
221 
225 FUNAPI_DLL_VISIBILITY const string &GetStatusCodeString(int status_code);
226 
231 FUNAPI_DLL_VISIBILITY bool Escape(const string &plain, string *out);
232 
237 FUNAPI_DLL_VISIBILITY bool Unescape(const string &url_encoded, string *out);
238 
239 } // namespace http
240 } // namespace fun
241 
242 #endif // INCLUDE_FUNAPI_NETWORK_HTTP_UTIL_H_
HTTP/1.0.
Definition: http_util.h:49
Data structure to hold HTTP request.
Definition: http_util.h:123
Method method
HTTP method.
Definition: http_util.h:112
StatusCode
Enum representing HTTP status code.
Definition: http_util.h:63
Header header
header fields
Definition: http_util.h:131
HTTP.
Definition: http_util.h:56
Invalid version.
Definition: http_util.h:48
TRACE method.
Definition: http_util.h:41
string body
request body
Definition: http_util.h:132
std::multimap< string, string, impl::util::CaseInsensitiveLess > Header
Datastructure to hold http header fields.
Definition: http_util.h:23
Version version
HTTP version.
Definition: http_util.h:140
DELETE method.
Definition: http_util.h:40
GetParameter get_parameter
Parameter if GET method.
Definition: http_util.h:116
uint32_t status_code
Response result.
Definition: http_util.h:141
std::map< string, string, impl::util::CaseInsensitiveLess > GetParameter
Datastructure to hold paramester associated HTTP GET method.
Definition: http_util.h:26
Invalid method.
Definition: http_util.h:35
string body
request body
Definition: http_util.h:118
Protocol
Enum type representing HTTP protocol type.
Definition: http_util.h:55
std::map< string, std::vector< string >, impl::util::CaseInsensitiveLess > GetParameter2
Datastructure to hold multiple value paramester associated HTTP GET method.
Definition: http_util.h:30
GET method.
Definition: http_util.h:36
PUT method.
Definition: http_util.h:39
Definition: json.h:18
HEAD method.
Definition: http_util.h:37
string body
response body
Definition: http_util.h:144
Version
Enum type representing HTTP version.
Definition: http_util.h:47
POST method.
Definition: http_util.h:38
Data structure to hold HTTP response.
Definition: http_util.h:137
HTTP/1.1.
Definition: http_util.h:50
Class to parse an URI string.
Definition: http_util.h:161
string request_uri
Request URI.
Definition: http_util.h:128
FUNAPI_DLL_VISIBILITY const string & GetMethodString(const Method &method)
Converts an HTTP method to string.
string request_ip
Request IP.
Definition: http_util.h:113
string status_message
message matching status_code
Definition: http_util.h:142
HTTPS.
Definition: http_util.h:57
FUNAPI_DLL_VISIBILITY bool Escape(const string &plain, string *out)
Converts the given string to a URL encoded string.
Header header
header fields
Definition: http_util.h:117
Version version
HTTP version.
Definition: http_util.h:129
string request_uri
Request URI.
Definition: http_util.h:114
Header header
header fields
Definition: http_util.h:143
Method
Enum type representing HTTP methods.
Definition: http_util.h:34
Version version
HTTP version.
Definition: http_util.h:115
OPTIONS method.
Definition: http_util.h:42
FUNAPI_DLL_VISIBILITY const string & GetStatusCodeString(int status_code)
Converts an HTTP status code to string.
#define DECLARE_CLASS_PTR(CLS)
Utility macro to forward-declare smart pointer types for a given class.
Definition: types.h:89
FUNAPI_DLL_VISIBILITY bool Unescape(const string &url_encoded, string *out)
Converts the given string to a URL decoded string.
Method method
HTTP method.
Definition: http_util.h:126
string request_ip
Request IP.
Definition: http_util.h:127
GetParameter2 get_parameter
Parameter if GET method.
Definition: http_util.h:130
Data structure to hold HTTP request.
Definition: http_util.h:109