CppCMS
http_request.h
1 //
3 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
4 //
5 // See accompanying file COPYING.TXT file for licensing details.
6 //
8 #ifndef CPPCMS_HTTP_REQUEST_H
9 #define CPPCMS_HTTP_REQUEST_H
10 
11 #include <cppcms/defs.h>
12 #include <booster/noncopyable.h>
13 #include <booster/hold_ptr.h>
14 #include <booster/shared_ptr.h>
15 #include <cppcms/http_content_type.h>
16 
17 #include <string>
18 #include <map>
19 #include <vector>
20 
21 namespace cppcms {
22 
23 namespace impl { namespace cgi { class connection; } }
24 namespace http {
25 
26  class cookie;
27  class file;
28 
34  class CPPCMS_API request : public booster::noncopyable {
35  public:
36 
37  // RFC 3875
38 
42  std::string auth_type();
46  unsigned long long content_length();
50  std::string content_type();
54  cppcms::http::content_type content_type_parsed();
58  std::string gateway_interface();
62  std::string path_info();
66  std::string path_translated();
70  std::string query_string();
74  std::string remote_addr();
78  std::string remote_host();
82  std::string remote_ident();
86  std::string remote_user();
90  std::string request_method();
94  std::string script_name();
98  std::string server_name();
102  unsigned server_port();
106  std::string server_protocol();
110  std::string server_software();
111 
112  // RFC 2616 request headers
113 
117  std::string http_accept();
121  std::string http_accept_charset();
125  std::string http_accept_encoding();
129  std::string http_accept_language();
133  std::string http_accept_ranges();
137  std::string http_authorization();
141  std::string http_cache_control();
145  std::string http_connection();
149  std::string http_cookie();
153  std::string http_expect();
157  std::string http_form();
161  std::string http_host();
165  std::string http_if_match();
169  std::string http_if_none_match();
170 
176  std::pair<bool,unsigned> http_max_forwards();
180  std::string http_pragma();
184  std::string http_proxy_authorization();
188  std::string http_range();
192  std::string http_referer();
196  std::string http_te();
200  std::string http_upgrade();
204  std::string http_user_agent();
208  std::string http_via();
212  std::string http_warn();
213 
217  std::string getenv(std::string const &);
221  std::string getenv(char const *);
225  char const *cgetenv(char const *);
229  std::map<std::string,std::string> getenv();
230 
231 
235  typedef std::multimap<std::string,std::string> form_type;
239  typedef std::map<std::string,cookie> cookies_type;
240 
244  typedef std::vector<booster::shared_ptr<file> > files_type;
245 
249  cookies_type const &cookies();
253  cookie const &cookie_by_name(std::string const &name);
258  std::string get(std::string const &name);
263  std::string post(std::string const &name);
267  form_type const &get();
271  form_type const &post();
275  form_type const &post_or_get();
276 
280  files_type files();
281 
291  std::pair<void *,size_t> raw_post_data();
292 
293  public:
295  request(impl::cgi::connection &);
296  ~request();
298  private:
299 
300  friend class impl::cgi::connection;
301 
302  void set_post_data(std::vector<char> &post_data);
303  void set_post_data(std::vector<booster::shared_ptr<file> > const &multipart);
304  bool prepare();
305 
306  bool parse_cookies();
307  std::string urlencoded_decode(char const *,char const *);
308  bool parse_form_urlencoded(char const *begin,char const *end,form_type &out);
309  bool read_key_value(
310  std::string::const_iterator &p,
311  std::string::const_iterator e,
312  std::string &key,
313  std::string &value);
314 
315  struct _data;
316  form_type get_;
317  form_type post_;
318  files_type files_;
319  cookies_type cookies_;
320  cppcms::http::content_type content_type_;
322  impl::cgi::connection *conn_;
323  };
324 
325 
326 } // namespace http
327 
328 } // namespace cppcms
329 
330 
331 
332 #endif
std::vector< booster::shared_ptr< file > > files_type
Definition: http_request.h:244
Class that represents parsed Content-Type header, this is immutable class. Once it is created its val...
Definition: http_content_type.h:23
Definition: log.h:25
Class that represents single HTTP Cookie Generally used in context of http::request and http::respons...
Definition: http_cookie.h:27
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15
std::multimap< std::string, std::string > form_type
Definition: http_request.h:235
std::map< std::string, cookie > cookies_type
Definition: http_request.h:239
This class represents all information related to the HTTP/CGI request.
Definition: http_request.h:34