Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace crow
{
routing_handle_result_ = handler_->handle_initial(req_, res);
// if no route is found for the request method, return the response without parsing or processing anything further.
if (!routing_handle_result_->rule_index)
if (!routing_handle_result_->rule_index && (req_.method != HTTPMethod::Options || routing_handle_result_->method == HTTPMethod::InternalMethodCount))
{
parser_.done();
need_to_call_after_handlers_ = true;
Expand All @@ -132,6 +132,12 @@ namespace crow
buffers_.emplace_back(expect_100_continue.data(), expect_100_continue.size());
do_write_sync(buffers_);
}
if (!routing_handle_result_->rule_index && req_.method == HTTPMethod::Options)
{
parser_.done();
need_to_call_after_handlers_ = true;
complete_request();
}
}

void handle()
Expand All @@ -157,7 +163,7 @@ namespace crow
is_invalid_request = true;
res = response(400);
}
else if (req_.upgrade)
else if (req_.upgrade && req_.method != HTTPMethod::Options)
{
// h2 or h2c headers
if (req_.get_header_value("upgrade").find("h2")==0)
Expand Down
6 changes: 3 additions & 3 deletions tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ TEST_CASE("middleware_cors")
CHECK(resp.find("Access-Control-Allow-Credentials: true") != std::string::npos);

resp = HttpClient::request(LOCALHOST_ADDRESS, port,
"OPTIONS /auth-origin / HTTP/1.1 \r\n\r\n");
"OPTIONS /auth-origin HTTP/1.1\r\n\r\n");
CHECK(resp.find("Access-Control-Allow-Origin: *") != std::string::npos);
CHECK(resp.find("Access-Control-Allow-Credentials: true") == std::string::npos);

Expand Down Expand Up @@ -2289,7 +2289,7 @@ TEST_CASE("simple_url_params")
// check multiple value, multiple types
HttpClient::request(LOCALHOST_ADDRESS, 45451,
"GET /params?int=100&double=123.45&boolean=1\r\n\r\n");

CHECK(utility::lexical_cast<int>(last_url_params.get("int")) == 100);
REQUIRE_THAT(123.45, Catch::Matchers::WithinAbs(utility::lexical_cast<double>(last_url_params.get("double")), 1e-9));
CHECK(utility::lexical_cast<bool>(last_url_params.get("boolean")));
Expand Down Expand Up @@ -4171,7 +4171,7 @@ TEST_CASE("option_header_passed_in_full")
};

std::string request =
"OPTIONS /echo HTTP/1.1\r\n";
"OPTIONS /echo HTTP/1.1\r\n\r\n";

auto res = make_request(request);
CHECK(res.find(ServerName) != std::string::npos);
Expand Down
Loading