mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
added automatic HEAD method handling
This commit is contained in:
parent
51a8a977d9
commit
6f5514743a
@ -357,6 +357,11 @@ namespace crow
|
||||
(*middlewares_, ctx_, req_, res);
|
||||
}
|
||||
|
||||
if (res.head)
|
||||
{
|
||||
res.body = "";
|
||||
}
|
||||
|
||||
std::string accept_encoding = req_.get_header_value("Accept-Encoding");
|
||||
if (!accept_encoding.empty() && res.compressed)
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ namespace crow
|
||||
std::string body; ///< The actual payload containing the response data.
|
||||
ci_map headers; ///< HTTP headers.
|
||||
bool compressed = true; ///< If compression is enabled and this is false, the individual response will not be compressed.
|
||||
bool head = false; ///< Whether this is a response to a HEAD request
|
||||
|
||||
/// Set the value of an existing header in the response.
|
||||
void set_header(std::string key, std::string value)
|
||||
|
@ -1075,8 +1075,15 @@ public:
|
||||
|
||||
void handle(const request& req, response& res)
|
||||
{
|
||||
HTTPMethod method_actual = req.method;
|
||||
if (req.method >= HTTPMethod::InternalMethodCount)
|
||||
return;
|
||||
else if (req.method == HTTPMethod::HEAD)
|
||||
{
|
||||
method_actual = HTTPMethod::GET;
|
||||
res.head = true;
|
||||
}
|
||||
|
||||
auto& per_method = per_methods_[(int)req.method];
|
||||
auto& trie = per_method.trie;
|
||||
auto& rules = per_method.rules;
|
||||
|
Loading…
Reference in New Issue
Block a user