00001 #ifndef CPP_WEB_SERVER_HTTP_REQUEST_HPP 00002 #define CPP_WEB_SERVER_HTTP_REQUEST_HPP 00003 00004 #include <string> 00005 #include <vector> 00006 #include <map> 00007 #include <boost/lexical_cast.hpp> 00008 #include "async_web_server_cpp/http_header.hpp" 00009 00010 namespace async_web_server_cpp 00011 { 00012 00016 struct HttpRequest 00017 { 00018 std::string method; 00019 std::string uri; 00020 int http_version_major; 00021 int http_version_minor; 00022 std::vector<HttpHeader> headers; 00023 00024 std::string path; 00025 std::string query; 00026 std::map<std::string, std::string> query_params; 00027 00028 bool has_header(const std::string &name) const; 00029 00030 std::string get_header_value_or_default(const std::string &name, 00031 const std::string &default_value) const; 00032 00033 00034 bool has_query_param(const std::string &name) const; 00035 00036 std::string get_query_param_value_or_default(const std::string &name, 00037 const std::string &default_value) const; 00038 00039 template<typename T> 00040 T get_query_param_value_or_default(const std::string &name, 00041 const T &default_value) const 00042 { 00043 std::map<std::string, std::string>::const_iterator itr = query_params.find(name); 00044 if (itr != query_params.end()) 00045 { 00046 try 00047 { 00048 return boost::lexical_cast<T>(itr->second); 00049 } 00050 catch (const boost::bad_lexical_cast &) 00051 { 00052 return default_value; 00053 } 00054 } 00055 else 00056 { 00057 return default_value; 00058 } 00059 } 00060 00061 bool parse_uri(); 00062 }; 00063 00064 } 00065 00066 #endif