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
std::map< std::string, std::string > query_params
std::string get_header_value_or_default(const std::string &name, const std::string &default_value) const
std::vector< HttpHeader > headers
T get_query_param_value_or_default(const std::string &name, const T &default_value) const
bool has_header(const std::string &name) const
std::string get_query_param_value_or_default(const std::string &name, const std::string &default_value) const
bool has_query_param(const std::string &name) const


async_web_server_cpp
Author(s): Mitchell Wills , Russel Toris
autogenerated on Mon Feb 28 2022 21:54:08