Menu

[r2024]: / framework / trunk / cppcms / http_request.h  Maximize  Restore  History

Download this file

344 lines (314 with data), 9.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCMS_HTTP_REQUEST_H
#define CPPCMS_HTTP_REQUEST_H
#include <cppcms/defs.h>
#include <booster/noncopyable.h>
#include <booster/hold_ptr.h>
#include <booster/shared_ptr.h>
#include <cppcms/http_content_type.h>
#include <string>
#include <map>
#include <vector>
namespace cppcms {
namespace impl { namespace cgi { class connection; } }
namespace http {
class cookie;
class file;
///
/// \brief This class represents all information related to the HTTP/CGI request.
///
/// It is usually accessed via http::context or application class
///
class CPPCMS_API request : public booster::noncopyable {
public:
// RFC 3875
///
/// CGI AUTH_TYPE environment variable
///
std::string auth_type();
///
/// CGI CONTENT_LENGTH environment variable
///
unsigned long long content_length();
///
/// CGI CONTENT_TYPE environment variable
///
std::string content_type();
///
/// Parsed CGI CONTENT_TYPE environment variable
///
cppcms::http::content_type content_type_parsed();
///
/// CGI GATEWAY_INTERFACE environment variable
///
std::string gateway_interface();
///
/// CGI PATH_INFO environment variable
///
std::string path_info();
///
/// CGI PATH_TRANSLATED environment variable
///
std::string path_translated();
///
/// CGI QUERY_STRING environment variable
///
std::string query_string();
///
/// CGI REMOTE_ADDR environment variable
///
std::string remote_addr();
///
/// CGI REMOTE_HOST environment variable
///
std::string remote_host();
///
/// CGI REMOTE_IDENT environment variable
///
std::string remote_ident();
///
/// CGI REMOTE_USER environment variable
///
std::string remote_user();
///
/// CGI REQUEST_METHOD environment variable
///
std::string request_method();
///
/// CGI SCRIPT_NAME environment variable
///
std::string script_name();
///
/// CGI SERVER_NAME environment variable
///
std::string server_name();
///
/// CGI SERVER_PORT environment variable
///
unsigned server_port();
///
/// CGI SERVER_PROTOCOL environment variable
///
std::string server_protocol();
///
/// CGI SERVER_SOFTWARE environment variable
///
std::string server_software();
// RFC 2616 request headers
///
/// CGI HTTP_ACCEPT variable representing Accept HTTP header
///
std::string http_accept();
///
/// CGI HTTP_ACCEPT_CHARSET variable representing Accept-Charset HTTP header
///
std::string http_accept_charset();
///
/// CGI HTTP_ACCEPT_ENCODING variable representing Accept-Encoding HTTP header
///
std::string http_accept_encoding();
///
/// CGI HTTP_ACCEPT_LANGUAGE variable representing Accept-Language HTTP header
///
std::string http_accept_language();
///
/// CGI HTTP_ACCEPT_RANGES variable representing Accept-Ranges HTTP header
///
std::string http_accept_ranges();
///
/// CGI HTTP_AUTHORIZATION variable representing Authorization HTTP header
///
std::string http_authorization();
///
/// CGI HTTP_CACHE_CONTROL variable representing Cache-Control HTTP header
///
std::string http_cache_control();
///
/// CGI HTTP_CONNECTION variable representing Connection HTTP header
///
std::string http_connection();
///
/// CGI HTTP_COOKIE variable representing Cookie HTTP header
///
std::string http_cookie();
///
/// CGI HTTP_EXPECT variable representing Expect HTTP header
///
std::string http_expect();
///
/// CGI HTTP_FORM variable representing Form HTTP header
///
std::string http_form();
///
/// CGI HTTP_HOST variable representing Host HTTP header
///
std::string http_host();
///
/// CGI HTTP_IF_MATCH variable representing If-Match HTTP header
///
std::string http_if_match();
///
/// CGI HTTP_IF_NONE_MATCH variable representing If-None-Match HTTP header
///
std::string http_if_none_match();
///
/// GGI HTTP_MAX_FORWARDS variable representing Http-Max-Forwards
///
/// Returns a pair of {true,HTTP_MAX_FORWARDS} if set or {false,0} otherwise
///
std::pair<bool,unsigned> http_max_forwards();
///
/// CGI HTTP_PRAGMA variable representing Pragma HTTP header
///
std::string http_pragma();
///
/// CGI HTTP_PROXY_AUTHORIZATION variable representing Proxy-Authorization HTTP header
///
std::string http_proxy_authorization();
///
/// CGI HTTP_RANGE variable representing Range HTTP header
///
std::string http_range();
///
/// CGI HTTP_REFERER variable representing Referer HTTP header
///
std::string http_referer();
///
/// CGI HTTP_TE variable representing Te HTTP header
///
std::string http_te();
///
/// CGI HTTP_UPGRADE variable representing Upgrade HTTP header
///
std::string http_upgrade();
///
/// CGI HTTP_USER_AGENT variable representing User-Agent HTTP header
///
std::string http_user_agent();
///
/// CGI HTTP_VIA variable representing Via HTTP header
///
std::string http_via();
///
/// CGI HTTP_WARN variable representing Warn HTTP header
///
std::string http_warn();
///
/// Get CGI environment variable by name. Returns empty string if the variable is not set
///
std::string getenv(std::string const &);
///
/// Get CGI environment variable by name. Returns empty string if the variable is not set
///
std::string getenv(char const *);
///
/// Get CGI environment variable by name. Returns empty string if the variable is not set
///
char const *cgetenv(char const *);
///
/// Get map of all CGI environment variable as key-value pairs.
///
std::map<std::string,std::string> getenv();
///
/// Type that represents from-data key-value pairs
///
typedef std::multimap<std::string,std::string> form_type;
///
/// Type of a map of cookie name to the cookie value
///
typedef std::map<std::string,cookie> cookies_type;
///
/// Type that represents all files uploaded in this request
///
typedef std::vector<booster::shared_ptr<file> > files_type;
///
/// Get all cookies sent with this request
///
cookies_type const &cookies();
///
/// Get cookie by its name, if not assigned returns empty cookie
///
cookie const &cookie_by_name(std::string const &name);
///
/// Fetch GET value by name, if name not exists or more then one
/// entry with same name exists, empty string is returned
///
std::string get(std::string const &name);
///
/// Fetch POST value by name, if name not exists or more then one
/// entry with same name exists, empty string is returned
///
std::string post(std::string const &name);
///
/// form-data GET part of request
///
form_type const &get();
///
/// form-data POST part of request
///
form_type const &post();
///
/// form-data POST or GET according to reuqest_method()
///
form_type const &post_or_get();
///
/// Get all uploaded files
///
files_type files();
///
/// Access to raw bits of POST data. If the POST request is empty or the request_type in not POST
/// {NULL,0} will be returned.
///
/// Note: when processing multipart/form-data POST request this function will always return {NULL,0} as
/// such requests maybe huge (file uploads of multiple hundreds of MB or even GB) that are would be stored in
/// temporary files instead of memory. In order to get access to POST data you'll have to use post(), get(), or files()
/// member functions.
///
std::pair<void *,size_t> raw_post_data();
public:
/// \cond INTERNAL
request(impl::cgi::connection &);
~request();
/// \endcond
private:
friend class impl::cgi::connection;
void set_post_data(std::vector<char> &post_data);
void set_post_data(std::vector<booster::shared_ptr<file> > const &multipart);
bool prepare();
bool parse_cookies();
std::string urlencoded_decode(char const *,char const *);
bool parse_form_urlencoded(char const *begin,char const *end,form_type &out);
bool read_key_value(
std::string::const_iterator &p,
std::string::const_iterator e,
std::string &key,
std::string &value);
struct _data;
form_type get_;
form_type post_;
files_type files_;
cookies_type cookies_;
cppcms::http::content_type content_type_;
booster::hold_ptr<_data> d;
impl::cgi::connection *conn_;
};
} // namespace http
} // namespace cppcms
#endif
MongoDB Logo MongoDB