iFun Engine API  1.0.0-b3795
Great Technology for Great Games
 All Classes Files Functions Variables Typedefs Macros
http_util.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2018 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 {
35  kUnknownMethod = 0,
36  kGet,
37  kHead,
38  kPost,
39  kPut,
40  kDelete,
41  kTrace,
42  kOptions,
43 };
44 
45 
47 enum Version {
48  kUnknownVersion = 0,
49  kHttp0,
50  kHttp1
51 };
52 
53 
55 enum Protocol {
56  kHttp = 0,
57  kHttps
58 };
59 
60 
63 enum StatusCode {
64  kContinue = 100,
65  kSwitchingProtocols = 101,
66  kOk = 200,
67  kCreated = 201,
68  kAccepted = 202,
69  kNonAuthoriativeInformation = 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,
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 Request {
110  DECLARE_CLASS_PTR(Request);
111 
112  Method method;
113  string request_ip;
114  string request_uri;
115  Version version;
116  GetParameter get_parameter;
117  Header header;
118  string body;
119 };
120 
121 
123 struct Request2 {
124  DECLARE_CLASS_PTR(Request);
125 
126  Method method;
127  string request_ip;
128  string request_uri;
129  Version version;
130  GetParameter2 get_parameter;
131  Header header;
132  string body;
133 };
134 
135 
137 struct Response {
138  DECLARE_CLASS_PTR(Response);
139 
140  Version version;
141  uint32_t status_code;
142  string status_message;
143  Header header;
144  string body;
145 };
146 
147 
161 class Uri {
162  public:
163 
165  Uri();
166 
169  explicit Uri(const string &uri_string);
170 
172  Uri(const Uri &rhs);
173 
176  bool Parse(const string &uri_string);
177 
180  const string &protocol() const;
181 
184  const string &host() const;
185 
188  uint16_t port() const;
189 
192  const string &path() const;
193 
196  const string &query_string() const;
197 
200  const string &raw() const;
201 
202  private:
203  void Reset();
204 
205  string protocol_;
206  string host_;
207  uint16_t port_;
208  string path_;
209  string query_string_;
210  string url_string_;
211 };
212 
213 
217 const string &GetMethodString(const Method &method);
218 
222 const string &GetStatusCodeString(int status_code);
223 
228 bool Escape(const string &plain, string *out);
229 
234 bool Unescape(const string &url_encoded, string *out);
235 
236 } // namespace http
237 } // namespace fun
238 
239 #endif // INCLUDE_FUNAPI_NETWORK_HTTP_UTIL_H_
Data structure to hold HTTP request.
Definition: http_util.h:123
Method method
HTTP method.
Definition: http_util.h:112
Header header
header fields
Definition: http_util.h:131
string body
request body
Definition: http_util.h:132
const string & raw() const
Returns the original URI.
const string & protocol() const
Returns protocol of a given URI.
Version version
HTTP version.
Definition: http_util.h:140
GetParameter get_parameter
Parameter if GET method.
Definition: http_util.h:116
uint16_t port() const
Returns port number of a given URI.
uint32_t status_code
Response result.
Definition: http_util.h:141
const string & path() const
Returns path part of a given URI.
bool Parse(const string &uri_string)
Parses the given URI.
string body
request body
Definition: http_util.h:118
string body
response body
Definition: http_util.h:144
Data structure to hold HTTP response.
Definition: http_util.h:137
Class to parse an URI string.
Definition: http_util.h:161
string request_uri
Request URI.
Definition: http_util.h:128
string request_ip
Request IP.
Definition: http_util.h:113
const string & host() const
Returns host part of a given URI.
string status_message
message matching status_code
Definition: http_util.h:142
const string & query_string() const
Returns query string part of a given URI.
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
Uri()
Default constructor. Holds empty URI.
Header header
header fields
Definition: http_util.h:143
Version version
HTTP version.
Definition: http_util.h:115
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