mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-09-30 20:52:31 +07:00
Fix #2315
This commit is contained in:
@@ -9646,6 +9646,10 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
|||||||
|
|
||||||
Request req;
|
Request req;
|
||||||
req.start_time_ = std::chrono::steady_clock::now();
|
req.start_time_ = std::chrono::steady_clock::now();
|
||||||
|
req.remote_addr = remote_addr;
|
||||||
|
req.remote_port = remote_port;
|
||||||
|
req.local_addr = local_addr;
|
||||||
|
req.local_port = local_port;
|
||||||
|
|
||||||
Response res;
|
Response res;
|
||||||
res.version = "HTTP/1.1";
|
res.version = "HTTP/1.1";
|
||||||
|
|||||||
@@ -6843,6 +6843,29 @@ TEST(ServerRequestParsingTest, InvalidSpaceInURL) {
|
|||||||
EXPECT_EQ("HTTP/1.1 400 Bad Request", out.substr(0, 24));
|
EXPECT_EQ("HTTP/1.1 400 Bad Request", out.substr(0, 24));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ServerRequestParsingTest, RemoteAddrSetOnBadRequest) {
|
||||||
|
Server svr;
|
||||||
|
|
||||||
|
svr.set_error_handler([&](const Request &req, Response & /*res*/) {
|
||||||
|
EXPECT_TRUE(!req.remote_addr.empty());
|
||||||
|
});
|
||||||
|
|
||||||
|
thread t = thread([&] { svr.listen(HOST, PORT); });
|
||||||
|
auto se = detail::scope_exit([&] {
|
||||||
|
svr.stop();
|
||||||
|
t.join();
|
||||||
|
ASSERT_FALSE(svr.is_running());
|
||||||
|
});
|
||||||
|
|
||||||
|
svr.wait_until_ready();
|
||||||
|
|
||||||
|
// Send an invalid request line to trigger Bad Request
|
||||||
|
const std::string bad_req = "BADMETHOD / HTTP/1.1\r\nHost: localhost\r\n\r\n";
|
||||||
|
std::string out;
|
||||||
|
ASSERT_TRUE(send_request(5, bad_req, &out));
|
||||||
|
EXPECT_EQ("HTTP/1.1 400 Bad Request", out.substr(0, 24));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(ServerRequestParsingTest, InvalidFieldValueContains_CR_LF_NUL) {
|
TEST(ServerRequestParsingTest, InvalidFieldValueContains_CR_LF_NUL) {
|
||||||
std::string out;
|
std::string out;
|
||||||
std::string request(
|
std::string request(
|
||||||
|
|||||||
Reference in New Issue
Block a user