2014-04-01 13:58:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
2014-04-14 15:31:51 +00:00
|
|
|
#include "common.h"
|
2014-09-10 21:32:41 +00:00
|
|
|
#include "ci_map.h"
|
2014-10-14 08:48:35 +00:00
|
|
|
#include "query_string.h"
|
2014-04-14 15:31:51 +00:00
|
|
|
|
2014-04-26 17:19:59 +00:00
|
|
|
namespace crow
|
2014-04-01 13:58:52 +00:00
|
|
|
{
|
2014-09-10 21:32:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-04-01 13:58:52 +00:00
|
|
|
struct request
|
|
|
|
{
|
2014-04-20 08:45:10 +00:00
|
|
|
HTTPMethod method;
|
2014-10-14 08:48:35 +00:00
|
|
|
std::string raw_url;
|
2014-04-01 13:58:52 +00:00
|
|
|
std::string url;
|
2014-10-14 08:48:35 +00:00
|
|
|
query_string url_params;
|
2014-09-10 21:32:41 +00:00
|
|
|
ci_map headers;
|
2014-04-01 13:58:52 +00:00
|
|
|
std::string body;
|
2014-09-06 16:24:45 +00:00
|
|
|
|
2014-09-12 03:14:54 +00:00
|
|
|
void* middleware_context{};
|
|
|
|
|
|
|
|
request()
|
|
|
|
: method(HTTPMethod::GET)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-14 08:48:35 +00: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))
|
2014-09-12 03:14:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-10 21:32:41 +00:00
|
|
|
void add_header(std::string key, std::string value)
|
|
|
|
{
|
|
|
|
headers.emplace(std::move(key), std::move(value));
|
|
|
|
}
|
|
|
|
|
2015-01-19 09:58:19 +00:00
|
|
|
const std::string& get_header_value(const std::string& key) const
|
2014-09-10 21:32:41 +00:00
|
|
|
{
|
|
|
|
return crow::get_header_value(headers, key);
|
|
|
|
}
|
|
|
|
|
2014-04-01 13:58:52 +00:00
|
|
|
};
|
|
|
|
}
|