4 #include <boost/asio.hpp>
6 #ifndef ASIO_STANDALONE
7 #define ASIO_STANDALONE
12 #include "crow/common.h"
13 #include "crow/ci_map.h"
14 #include "crow/query_string.h"
19 namespace asio = boost::asio;
26 if (headers.count(key))
28 return headers.find(key)->second;
30 static std::string empty;
44 unsigned char http_ver_major, http_ver_minor;
49 void* middleware_context{};
50 void* middleware_container{};
51 asio::io_service* io_service{};
55 method(HTTPMethod::Get)
59 request(HTTPMethod method_, std::string raw_url_, std::string url_,
query_string url_params_, ci_map headers_, std::string body_,
unsigned char http_major,
unsigned char http_minor,
bool has_keep_alive,
bool has_close_connection,
bool is_upgrade):
60 method(method_),
raw_url(std::move(raw_url_)),
url(std::move(url_)),
url_params(std::move(url_params_)), headers(std::move(headers_)), body(std::move(body_)), http_ver_major(http_major), http_ver_minor(http_minor),
keep_alive(has_keep_alive),
close_connection(has_close_connection),
upgrade(is_upgrade)
63 void add_header(std::string key, std::string value)
65 headers.emplace(std::move(key), std::move(value));
68 const std::string& get_header_value(
const std::string& key)
const
73 bool check_version(
unsigned char major,
unsigned char minor)
const
75 return http_ver_major == major && http_ver_minor == minor;
88 template<
typename CompletionHandler>
89 void post(CompletionHandler handler)
91 io_service->post(handler);
95 template<
typename CompletionHandler>
98 io_service->dispatch(handler);
A class to represent any data coming after the ? in the request URL into key-value pairs.
Definition: query_string.h:294
The main namespace of the library. In this namespace is defined the most important classes and functi...
const std::string & get_header_value(const T &headers, const std::string &key)
Find and return the value associated with the key. (returns an empty string if nothing is found)
Definition: http_request.h:24
An HTTP request.
Definition: http_request.h:36
void post(CompletionHandler handler)
Send data to whoever made this request with a completion handler and return immediately.
Definition: http_request.h:89
bool close_connection
Whether or not the server should shut down the TCP connection once a response is sent.
Definition: http_request.h:46
bool keep_alive
Whether or not the server should send a connection: Keep-Alive header to the client.
Definition: http_request.h:45
std::string raw_url
The full URL containing the ? and URL parameters.
Definition: http_request.h:38
query_string url_params
The parameters associated with the request. (everything after the ? in the URL)
Definition: http_request.h:40
request()
Construct an empty request. (sets the method to GET)
Definition: http_request.h:54
std::string url
The endpoint without any parameters.
Definition: http_request.h:39
std::string remote_ip_address
The IP address from which the request was sent.
Definition: http_request.h:43
request(HTTPMethod method_, std::string raw_url_, std::string url_, query_string url_params_, ci_map headers_, std::string body_, unsigned char http_major, unsigned char http_minor, bool has_keep_alive, bool has_close_connection, bool is_upgrade)
Construct a request with all values assigned.
Definition: http_request.h:59
void dispatch(CompletionHandler handler)
Send data to whoever made this request with a completion handler.
Definition: http_request.h:96
bool upgrade
Whether or noth the server should change the HTTP connection to a different connection.
Definition: http_request.h:47
const query_string get_body_params() const
Get the body as parameters in QS format.
Definition: http_request.h:82