Menu

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

Download this file

383 lines (349 with data), 10.2 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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#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;
class content_limits;
class content_filter;
class basic_content_filter;
///
/// \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 (content) data. If the content is empty if raw_content_filter is installed
/// or multipart/form-data is handled the read_post_data().second will be 0;
///
/// Note: when processing multipart/form-data returns chunk of zero size 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();
///
/// Get content limits for incoming data processing
///
/// \ver{v1_2}
content_limits &limits();
///
/// Get installed content filter, returns 0 if it is not installed, no ownership is transfered
///
/// \ver{v1_2}
basic_content_filter *content_filter();
///
/// Installs content filter. If another filter installed it is removed
///
/// \ver{v1_2}
void set_content_filter(basic_content_filter &flt);
///
/// Installs new content filter (or removes existing), the ownership of new filter is transfered to the request object
///
/// \ver{v1_2}
void reset_content_filter(basic_content_filter *flt = 0);
///
/// Release existing content filter owned by request
///
/// \ver{v1_2}
basic_content_filter *release_content_filter();
///
/// Returns true when full request content is ready
///
/// \ver{v1_2}
bool is_ready();
///
/// Set the size of the buffer for content that isn't loaded to memory directly,
/// like for example multipart/form-data, default is defined in configuration as
/// service.input_buffer_size and defaults to 65536
///
/// \ver{v1_2}
void setbuf(int size);
public:
/// \cond INTERNAL
request(impl::cgi::connection &);
~request();
/// \endcond
private:
friend class context;
friend class impl::cgi::connection;
void set_filter(basic_content_filter *ptr,bool owns);
int on_content_start();
void on_error();
int on_content_progress(size_t n);
std::pair<char *,size_t > get_buffer();
bool size_ok(file &f,long long size);
std::pair<char *,size_t> get_content_buffer();
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