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  class content_limits;
29  class content_filter;
30  class basic_content_filter;
31 
37  class CPPCMS_API request : public booster::noncopyable {
38  public:
39 
40  // RFC 3875
41 
45  std::string auth_type();
49  unsigned long long content_length();
53  std::string content_type();
57  cppcms::http::content_type content_type_parsed();
61  std::string gateway_interface();
65  std::string path_info();
69  std::string path_translated();
73  std::string query_string();
77  std::string remote_addr();
81  std::string remote_host();
85  std::string remote_ident();
89  std::string remote_user();
93  std::string request_method();
97  std::string script_name();
101  std::string server_name();
105  unsigned server_port();
109  std::string server_protocol();
113  std::string server_software();
114 
115  // RFC 2616 request headers
116 
120  std::string http_accept();
124  std::string http_accept_charset();
128  std::string http_accept_encoding();
132  std::string http_accept_language();
136  std::string http_accept_ranges();
140  std::string http_authorization();
144  std::string http_cache_control();
148  std::string http_connection();
152  std::string http_cookie();
156  std::string http_expect();
160  std::string http_form();
164  std::string http_host();
168  std::string http_if_match();
172  std::string http_if_none_match();
173 
179  std::pair<bool,unsigned> http_max_forwards();
183  std::string http_pragma();
187  std::string http_proxy_authorization();
191  std::string http_range();
195  std::string http_referer();
199  std::string http_te();
203  std::string http_upgrade();
207  std::string http_user_agent();
211  std::string http_via();
215  std::string http_warn();
216 
220  std::string getenv(std::string const &);
224  std::string getenv(char const *);
228  char const *cgetenv(char const *);
232  std::map<std::string,std::string> getenv();
233 
234 
238  typedef std::multimap<std::string,std::string> form_type;
242  typedef std::map<std::string,cookie> cookies_type;
243 
247  typedef std::vector<booster::shared_ptr<file> > files_type;
248 
252  cookies_type const &cookies();
256  cookie const &cookie_by_name(std::string const &name);
261  std::string get(std::string const &name);
266  std::string post(std::string const &name);
270  form_type const &get();
274  form_type const &post();
278  form_type const &post_or_get();
279 
283  files_type files();
284 
294  std::pair<void *,size_t> raw_post_data();
295 
300  content_limits &limits();
301 
306  basic_content_filter *content_filter();
307 
312  void set_content_filter(basic_content_filter &flt);
313 
318  void reset_content_filter(basic_content_filter *flt = 0);
323  basic_content_filter *release_content_filter();
328  bool is_ready();
335  void setbuf(int size);
336  public:
338  request(impl::cgi::connection &);
339  ~request();
341  private:
342  friend class context;
343  friend class impl::cgi::connection;
344 
345  void set_filter(basic_content_filter *ptr,bool owns);
346 
347  int on_content_start();
348  void on_error();
349  int on_content_progress(size_t n);
350  std::pair<char *,size_t > get_buffer();
351 
352  bool size_ok(file &f,long long size);
353 
354  std::pair<char *,size_t> get_content_buffer();
355  bool prepare();
356  bool parse_cookies();
357  std::string urlencoded_decode(char const *,char const *);
358  bool parse_form_urlencoded(char const *begin,char const *end,form_type &out);
359  bool read_key_value(
360  std::string::const_iterator &p,
361  std::string::const_iterator e,
362  std::string &key,
363  std::string &value);
364 
365  struct _data;
366  form_type get_;
367  form_type post_;
368  files_type files_;
369  cookies_type cookies_;
370  cppcms::http::content_type content_type_;
372  impl::cgi::connection *conn_;
373  };
374 
375 
376 } // namespace http
377 
378 } // namespace cppcms
379 
380 
381 
382 #endif
std::vector< booster::shared_ptr< file > > files_type
Definition: http_request.h:247
Class that represents parsed Content-Type header, this is immutable class. Once it is created its val...
Definition: http_content_type.h:23
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
context is a central class that holds all specific connection related information. It encapsulates CGI request and response, cache, session and locale information
Definition: http_context.h:47
Definition: http_content_filter.h:127
This class holds a uploaded file, it is generally fetched via widgets::file or via http::request::fil...
Definition: http_file.h:38
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:238
std::map< std::string, cookie > cookies_type
Definition: http_request.h:242
Definition: http_content_filter.h:52
This class represents all information related to the HTTP/CGI request.
Definition: http_request.h:37