onion-wownero-blockchain-ex.../ext/crow/http_request.h

69 lines
1.7 KiB
C
Raw Normal View History

2016-04-06 07:53:37 +01:00
#pragma once
#include "common.h"
#include "ci_map.h"
#include "query_string.h"
2016-09-06 11:34:07 +01:00
#include <boost/asio.hpp>
2016-04-06 07:53:37 +01:00
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;
}
2016-09-06 11:34:07 +01:00
struct DetachHelper;
2016-04-06 07:53:37 +01:00
struct request
{
HTTPMethod method;
std::string raw_url;
std::string url;
query_string url_params;
ci_map headers;
std::string body;
void* middleware_context{};
2016-09-06 11:34:07 +01:00
boost::asio::io_service* io_service{};
2016-04-06 07:53:37 +01:00
request()
2016-09-06 11:34:07 +01:00
: method(HTTPMethod::Get)
2016-04-06 07:53:37 +01:00
{
}
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);
}
2016-09-06 11:34:07 +01:00
template<typename CompletionHandler>
void post(CompletionHandler handler)
{
io_service->post(handler);
}
template<typename CompletionHandler>
void dispatch(CompletionHandler handler)
{
io_service->dispatch(handler);
}
2016-04-06 07:53:37 +01:00
};
}