http_request.hpp
Go to the documentation of this file.
1 #ifndef CPP_WEB_SERVER_HTTP_REQUEST_HPP
2 #define CPP_WEB_SERVER_HTTP_REQUEST_HPP
3 
5 
6 #include <boost/lexical_cast.hpp>
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 namespace async_web_server_cpp
13 {
14 
19 {
20  std::string method;
21  std::string uri;
24  std::vector<HttpHeader> headers;
25 
26  std::string path;
27  std::string query;
28  std::map<std::string, std::string> query_params;
29 
30  bool has_header(const std::string& name) const;
31 
32  std::string
33  get_header_value_or_default(const std::string& name,
34  const std::string& default_value) const;
35 
36  bool has_query_param(const std::string& name) const;
37 
38  std::string
39  get_query_param_value_or_default(const std::string& name,
40  const std::string& default_value) const;
41 
42  template<typename T>
43  T get_query_param_value_or_default(const std::string& name,
44  const T& default_value) const
45  {
46  std::map<std::string, std::string>::const_iterator itr =
47  query_params.find(name);
48  if (itr != query_params.end())
49  {
50  try
51  {
52  return boost::lexical_cast<T>(itr->second);
53  }
54  catch (const boost::bad_lexical_cast&)
55  {
56  return default_value;
57  }
58  }
59  else
60  {
61  return default_value;
62  }
63  }
64 
65  bool parse_uri();
66 };
67 
68 } // namespace async_web_server_cpp
69 
70 #endif
async_web_server_cpp::HttpRequest::parse_uri
bool parse_uri()
Definition: http_request.cpp:12
http_header.hpp
async_web_server_cpp
Definition: http_connection.hpp:14
async_web_server_cpp::HttpRequest::has_query_param
bool has_query_param(const std::string &name) const
Definition: http_request.cpp:75
async_web_server_cpp::HttpRequest::http_version_major
int http_version_major
Definition: http_request.hpp:22
async_web_server_cpp::HttpRequest::has_header
bool has_header(const std::string &name) const
Definition: http_request.cpp:50
async_web_server_cpp::HttpRequest::path
std::string path
Definition: http_request.hpp:26
async_web_server_cpp::HttpRequest::get_query_param_value_or_default
T get_query_param_value_or_default(const std::string &name, const T &default_value) const
Definition: http_request.hpp:43
async_web_server_cpp::HttpRequest
Definition: http_request.hpp:18
async_web_server_cpp::HttpRequest::get_query_param_value_or_default
std::string get_query_param_value_or_default(const std::string &name, const std::string &default_value) const
Definition: http_request.cpp:82
async_web_server_cpp::HttpRequest::get_header_value_or_default
std::string get_header_value_or_default(const std::string &name, const std::string &default_value) const
Definition: http_request.cpp:62
async_web_server_cpp::HttpRequest::method
std::string method
Definition: http_request.hpp:20
async_web_server_cpp::HttpRequest::headers
std::vector< HttpHeader > headers
Definition: http_request.hpp:24
async_web_server_cpp::HttpRequest::query_params
std::map< std::string, std::string > query_params
Definition: http_request.hpp:28
async_web_server_cpp::HttpRequest::http_version_minor
int http_version_minor
Definition: http_request.hpp:23
async_web_server_cpp::HttpRequest::uri
std::string uri
Definition: http_request.hpp:21
async_web_server_cpp::HttpRequest::query
std::string query
Definition: http_request.hpp:27


async_web_server_cpp
Author(s): Mitchell Wills , Russel Toris
autogenerated on Tue Mar 1 2022 23:49:06