Skip to content
Merged
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 && !routing_handle_result_->catch_all)
if (!routing_handle_result_->rule_index && !routing_handle_result_->catch_all && (req_.method != HTTPMethod::Options || routing_handle_result_->method == HTTPMethod::InternalMethodCount))
{
parser_.done();
need_to_call_after_handlers_ = true;
Expand All @@ -136,6 +136,12 @@ namespace crow
CROW_LOG_ERROR << ec << " buffer write error happened while handling sending continuation buffer header";
}
}
if (!routing_handle_result_->rule_index && !routing_handle_result_->catch_all && req_.method == HTTPMethod::Options)
{
parser_.done();
need_to_call_after_handlers_ = true;
complete_request();
}
}

void handle()
Expand All @@ -161,7 +167,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
4 changes: 2 additions & 2 deletions tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,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 @@ -2800,7 +2800,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