iFun Engine API  1.0.0-b3630
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-2015 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 };
43 
44 
46 enum Version {
47  kUnknownVersion = 0,
48  kHttp0,
49  kHttp1
50 };
51 
52 
54 enum Protocol {
55  kHttp = 0,
56  kHttps
57 };
58 
59 
62 enum StatusCode {
63  kContinue = 100,
64  kSwitchingProtocols = 101,
65  kOk = 200,
66  kCreated = 201,
67  kAccepted = 202,
68  kNonAuthoriativeInformation = 203,
69  kNoContent = 204,
70  kResetContent = 205,
71  kPartialContent = 206,
72  kMultipleChoices = 300,
73  kMovedPermanently = 301,
74  kFound = 302,
75  kSeeOther = 303,
76  kNotModified = 304,
77  kUseProxy = 305,
78  kTemporaryRedirect = 307,
79  kBadRequest = 400,
80  kUnauthorized = 401,
81  kPaymentRequired = 402,
82  kForbidden = 403,
83  kNotFound = 404,
84  kMethodNotAllowed = 405,
85  kNotAcceptable = 406,
86  kProxyAuthenticationRequired = 407,
87  kRequestTimeout = 408,
88  kConflict = 409,
89  kGone = 410,
90  kLengthRequired = 411,
91  kPreconditionFailed = 412,
92  kRequestEntityTooLarge = 413,
93  kRequestUriTooLong = 414,
94  kUnsupportedMediaType = 415,
95  kRequestRangeNotSatisfiable = 416,
96  kExpectationFailed = 417,
97  kTooManyRequests = 429,
98  kInternalServerError = 500,
99  kNotImplemented = 501,
100  kBadGateway = 502,
101  kServiceUnavailable = 503,
102  kGatewayTimeout = 504,
103  kHttpVersionNotSupported = 505
104 };
105 
106 
108 struct Request {
109  DECLARE_CLASS_PTR(Request);
110 
111  Method method;
112  string request_ip;
113  string request_uri;
114  Version version;
115  GetParameter get_parameter;
116  Header header;
117  string body;
118 };
119 
120 
122 struct Request2 {
123  DECLARE_CLASS_PTR(Request);
124 
125  Method method;
126  string request_ip;
127  string request_uri;
128  Version version;
129  GetParameter2 get_parameter;
130  Header header;
131  string body;
132 };
133 
134 
136 struct Response {
137  DECLARE_CLASS_PTR(Response);
138 
139  Version version;
140  uint32_t status_code;
141  string status_message;
142  Header header;
143  string body;
144 };
145 
146 
160 class Uri {
161  public:
162 
164  Uri();
165 
168  explicit Uri(const string &uri_string);
169 
171  Uri(const Uri &rhs);
172 
175  bool Parse(const string &uri_string);
176 
179  const string &protocol() const;
180 
183  const string &host() const;
184 
187  uint16_t port() const;
188 
191  const string &path() const;
192 
195  const string &query_string() const;
196 
199  const string &raw() const;
200 
201  private:
202  void Reset();
203 
204  string protocol_;
205  string host_;
206  uint16_t port_;
207  string path_;
208  string query_string_;
209  string url_string_;
210 };
211 
212 
216 const string &GetMethodString(const Method &method);
217 
221 const string &GetStatusCodeString(int status_code);
222 
227 bool Escape(const string &plain, string *out);
228 
233 bool Unescape(const string &url_encoded, string *out);
234 
235 } // namespace http
236 } // namespace fun
237 
238 #endif // INCLUDE_FUNAPI_NETWORK_HTTP_UTIL_H_
Data structure to hold HTTP request.
Definition: http_util.h:122
Method method
HTTP method.
Definition: http_util.h:111
Header header
header fields
Definition: http_util.h:130
string body
request body
Definition: http_util.h:131
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:139
GetParameter get_parameter
Parameter if GET method.
Definition: http_util.h:115
uint16_t port() const
Returns port number of a given URI.
uint32_t status_code
Response result.
Definition: http_util.h:140
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:117
string body
response body
Definition: http_util.h:143
Data structure to hold HTTP response.
Definition: http_util.h:136
Class to parse an URI string.
Definition: http_util.h:160
string request_uri
Request URI.
Definition: http_util.h:127
string request_ip
Request IP.
Definition: http_util.h:112
const string & host() const
Returns host part of a given URI.
string status_message
message matching status_code
Definition: http_util.h:141
const string & query_string() const
Returns query string part of a given URI.
Header header
header fields
Definition: http_util.h:116
Version version
HTTP version.
Definition: http_util.h:128
string request_uri
Request URI.
Definition: http_util.h:113
Uri()
Default constructor. Holds empty URI.
Header header
header fields
Definition: http_util.h:142
Version version
HTTP version.
Definition: http_util.h:114
Method method
HTTP method.
Definition: http_util.h:125
string request_ip
Request IP.
Definition: http_util.h:126
GetParameter2 get_parameter
Parameter if GET method.
Definition: http_util.h:129
Data structure to hold HTTP request.
Definition: http_util.h:108