CppCMS
|
00001 00002 // 00003 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> 00004 // 00005 // See accompanying file COPYING.TXT file for licensing details. 00006 // 00008 #ifndef CPPCMS_HTTP_REQUEST_H 00009 #define CPPCMS_HTTP_REQUEST_H 00010 00011 #include <cppcms/defs.h> 00012 #include <booster/noncopyable.h> 00013 #include <booster/hold_ptr.h> 00014 #include <booster/shared_ptr.h> 00015 #include <cppcms/http_content_type.h> 00016 00017 #include <string> 00018 #include <map> 00019 #include <vector> 00020 00021 namespace cppcms { 00022 00023 namespace impl { namespace cgi { class connection; } } 00024 namespace http { 00025 00026 class cookie; 00027 class file; 00028 00034 class CPPCMS_API request : public booster::noncopyable { 00035 public: 00036 00037 // RFC 3875 00038 00042 std::string auth_type(); 00046 unsigned long long content_length(); 00050 std::string content_type(); 00054 cppcms::http::content_type content_type_parsed(); 00058 std::string gateway_interface(); 00062 std::string path_info(); 00066 std::string path_translated(); 00070 std::string query_string(); 00074 std::string remote_addr(); 00078 std::string remote_host(); 00082 std::string remote_ident(); 00086 std::string remote_user(); 00090 std::string request_method(); 00094 std::string script_name(); 00098 std::string server_name(); 00102 unsigned server_port(); 00106 std::string server_protocol(); 00110 std::string server_software(); 00111 00112 // RFC 2616 request headers 00113 00117 std::string http_accept(); 00121 std::string http_accept_charset(); 00125 std::string http_accept_encoding(); 00129 std::string http_accept_language(); 00133 std::string http_accept_ranges(); 00137 std::string http_authorization(); 00141 std::string http_cache_control(); 00145 std::string http_connection(); 00149 std::string http_cookie(); 00153 std::string http_expect(); 00157 std::string http_form(); 00161 std::string http_host(); 00165 std::string http_if_match(); 00169 std::string http_if_none_match(); 00170 00176 std::pair<bool,unsigned> http_max_forwards(); 00180 std::string http_pragma(); 00184 std::string http_proxy_authorization(); 00188 std::string http_range(); 00192 std::string http_referer(); 00196 std::string http_te(); 00200 std::string http_upgrade(); 00204 std::string http_user_agent(); 00208 std::string http_via(); 00212 std::string http_warn(); 00213 00217 std::string getenv(std::string const &); 00221 std::string getenv(char const *); 00225 char const *cgetenv(char const *); 00229 std::map<std::string,std::string> getenv(); 00230 00231 00235 typedef std::multimap<std::string,std::string> form_type; 00239 typedef std::map<std::string,cookie> cookies_type; 00240 00244 typedef std::vector<booster::shared_ptr<file> > files_type; 00245 00249 cookies_type const &cookies(); 00253 cookie const &cookie_by_name(std::string const &name); 00258 std::string get(std::string const &name); 00263 std::string post(std::string const &name); 00267 form_type const &get(); 00271 form_type const &post(); 00275 form_type const &post_or_get(); 00276 00280 files_type files(); 00281 00291 std::pair<void *,size_t> raw_post_data(); 00292 00293 public: 00295 request(impl::cgi::connection &); 00296 ~request(); 00298 private: 00299 00300 friend class impl::cgi::connection; 00301 00302 void set_post_data(std::vector<char> &post_data); 00303 void set_post_data(std::vector<booster::shared_ptr<file> > const &multipart); 00304 bool prepare(); 00305 00306 bool parse_cookies(); 00307 std::string urlencoded_decode(char const *,char const *); 00308 bool parse_form_urlencoded(char const *begin,char const *end,form_type &out); 00309 bool read_key_value( 00310 std::string::const_iterator &p, 00311 std::string::const_iterator e, 00312 std::string &key, 00313 std::string &value); 00314 00315 struct _data; 00316 form_type get_; 00317 form_type post_; 00318 files_type files_; 00319 cookies_type cookies_; 00320 cppcms::http::content_type content_type_; 00321 booster::hold_ptr<_data> d; 00322 impl::cgi::connection *conn_; 00323 }; 00324 00325 00326 } // namespace http 00327 00328 } // namespace cppcms 00329 00330 00331 00332 #endif