Skip to content

Commit

Permalink
fix: call after_handlers for legitimate requests without body part
Browse files Browse the repository at this point in the history
  • Loading branch information
junekhan committed Feb 21, 2024
1 parent 1e864a2 commit 047e9ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace crow
if (!routing_handle_result_->rule_index)
{
parser_.done();
need_to_call_after_handlers_ = true;
complete_request();
}
}
Expand Down
22 changes: 18 additions & 4 deletions tests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,15 +1869,29 @@ TEST_CASE("middleware_cors")
return "-";
});

auto _ = app.bindaddr(LOCALHOST_ADDRESS).port(45451).run_async();
const auto port = 33333;
auto _ = app.bindaddr(LOCALHOST_ADDRESS).port(port).run_async();

app.wait_for_server_start();
asio::io_service is;

{
asio::ip::tcp::socket c(is);
c.connect(asio::ip::tcp::endpoint(
asio::ip::address::from_string(LOCALHOST_ADDRESS), 45451));
asio::ip::address::from_string(LOCALHOST_ADDRESS), port));

c.send(asio::buffer("OPTIONS / HTTP/1.1\r\n\r\n"));

c.receive(asio::buffer(buf, 2048));
c.close();

CHECK(std::string(buf).find("Access-Control-Allow-Origin: *") != std::string::npos);
}

{
asio::ip::tcp::socket c(is);
c.connect(asio::ip::tcp::endpoint(
asio::ip::address::from_string(LOCALHOST_ADDRESS), port));

c.send(asio::buffer("GET /\r\n\r\n"));

Expand All @@ -1890,7 +1904,7 @@ TEST_CASE("middleware_cors")
{
asio::ip::tcp::socket c(is);
c.connect(asio::ip::tcp::endpoint(
asio::ip::address::from_string(LOCALHOST_ADDRESS), 45451));
asio::ip::address::from_string(LOCALHOST_ADDRESS), port));

c.send(asio::buffer("GET /origin\r\n\r\n"));

Expand All @@ -1903,7 +1917,7 @@ TEST_CASE("middleware_cors")
{
asio::ip::tcp::socket c(is);
c.connect(asio::ip::tcp::endpoint(
asio::ip::address::from_string(LOCALHOST_ADDRESS), 45451));
asio::ip::address::from_string(LOCALHOST_ADDRESS), port));

c.send(asio::buffer("GET /nocors/path\r\n\r\n"));

Expand Down

0 comments on commit 047e9ff

Please sign in to comment.