mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
added tests and fixed small issues
moved body handling to Response.end() and fixed a bug where a 404 was not returned on a route that doesn't exist
This commit is contained in:
parent
06226b86a7
commit
ec566f87ef
@ -357,11 +357,6 @@ namespace crow
|
||||
(*middlewares_, ctx_, req_, res);
|
||||
}
|
||||
|
||||
if (res.no_body)
|
||||
{
|
||||
res.body = "";
|
||||
}
|
||||
|
||||
std::string accept_encoding = req_.get_header_value("Accept-Encoding");
|
||||
if (!accept_encoding.empty() && res.compressed)
|
||||
{
|
||||
|
@ -148,7 +148,10 @@ namespace crow
|
||||
if (!completed_)
|
||||
{
|
||||
completed_ = true;
|
||||
|
||||
if (no_body)
|
||||
{
|
||||
body = "";
|
||||
}
|
||||
if (complete_request_handler_)
|
||||
{
|
||||
complete_request_handler_();
|
||||
|
@ -1119,7 +1119,7 @@ namespace crow
|
||||
allow += method_name((HTTPMethod)i) + ", ";
|
||||
}
|
||||
}
|
||||
if (allow.size() > 0)
|
||||
if (allow != "OPTIONS, HEAD, ")
|
||||
{
|
||||
allow = allow.substr(0, allow.size()-2);
|
||||
res = response(204);
|
||||
|
@ -378,6 +378,54 @@ TEST_CASE("http_method")
|
||||
|
||||
CHECK(405 == res.code);
|
||||
}
|
||||
|
||||
{
|
||||
request req;
|
||||
response res;
|
||||
|
||||
req.url = "/get_only";
|
||||
req.method = "HEAD"_method;
|
||||
app.handle(req, res);
|
||||
|
||||
CHECK(200 == res.code);
|
||||
CHECK("" == res.body);
|
||||
}
|
||||
|
||||
{
|
||||
request req;
|
||||
response res;
|
||||
|
||||
req.url = "/";
|
||||
req.method = "OPTIONS"_method;
|
||||
app.handle(req, res);
|
||||
|
||||
CHECK(204 == res.code);
|
||||
CHECK("OPTIONS, HEAD, GET, POST" == res.get_header_value("Allow"));
|
||||
}
|
||||
|
||||
{
|
||||
request req;
|
||||
response res;
|
||||
|
||||
req.url = "/does_not_exist";
|
||||
req.method = "OPTIONS"_method;
|
||||
app.handle(req, res);
|
||||
|
||||
CHECK(404 == res.code);
|
||||
}
|
||||
|
||||
{
|
||||
request req;
|
||||
response res;
|
||||
|
||||
req.url = "/*";
|
||||
req.method = "OPTIONS"_method;
|
||||
app.handle(req, res);
|
||||
|
||||
CHECK(204 == res.code);
|
||||
CHECK("OPTIONS, HEAD, GET, POST, PATCH, PURGE" == res.get_header_value("Allow"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("server_handling_error_request")
|
||||
|
Loading…
Reference in New Issue
Block a user