aboutsummaryrefslogtreecommitdiffstats
path: root/include/crow/http_request.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/crow/http_request.h')
-rw-r--r--include/crow/http_request.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/include/crow/http_request.h b/include/crow/http_request.h
new file mode 100644
index 0000000..a70c299
--- /dev/null
+++ b/include/crow/http_request.h
@@ -0,0 +1,69 @@
+#pragma once
+
+#include <boost/asio.hpp>
+
+#include "crow/common.h"
+#include "crow/ci_map.h"
+#include "crow/query_string.h"
+
+namespace crow
+{
+ template <typename T>
+ inline const std::string& get_header_value(const T& headers, const std::string& key)
+ {
+ if (headers.count(key))
+ {
+ return headers.find(key)->second;
+ }
+ static std::string empty;
+ return empty;
+ }
+
+ struct DetachHelper;
+
+ struct request
+ {
+ HTTPMethod method;
+ std::string raw_url;
+ std::string url;
+ query_string url_params;
+ ci_map headers;
+ std::string body;
+
+ void* middleware_context{};
+ boost::asio::io_service* io_service{};
+
+ request()
+ : method(HTTPMethod::Get)
+ {
+ }
+
+ request(HTTPMethod method, std::string raw_url, std::string url, query_string url_params, ci_map headers, std::string body)
+ : 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))
+ {
+ }
+
+ void add_header(std::string key, std::string value)
+ {
+ headers.emplace(std::move(key), std::move(value));
+ }
+
+ const std::string& get_header_value(const std::string& key) const
+ {
+ return crow::get_header_value(headers, key);
+ }
+
+ template<typename CompletionHandler>
+ void post(CompletionHandler handler)
+ {
+ io_service->post(handler);
+ }
+
+ template<typename CompletionHandler>
+ void dispatch(CompletionHandler handler)
+ {
+ io_service->dispatch(handler);
+ }
+
+ };
+}