mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Apply range header base on response status code (#1806)
* Enable ignoring range header to generate customized response * Apply range header base on response status code
This commit is contained in:
parent
2064462c35
commit
560854a961
2 changed files with 26 additions and 3 deletions
23
test/test.cc
23
test/test.cc
|
@ -1890,6 +1890,11 @@ protected:
|
|||
[&](const Request & /*req*/, Response &res) {
|
||||
res.set_content("abcdefg", "text/plain");
|
||||
})
|
||||
.Get("/with-range-customized-response",
|
||||
[&](const Request & /*req*/, Response &res) {
|
||||
res.status = StatusCode::BadRequest_400;
|
||||
res.set_content(JSON_DATA, "application/json");
|
||||
})
|
||||
.Post("/chunked",
|
||||
[&](const Request &req, Response & /*res*/) {
|
||||
EXPECT_EQ(req.body, "dechunked post body");
|
||||
|
@ -3166,6 +3171,24 @@ TEST_F(ServerTest, GetWithRangeMultipartOffsetGreaterThanContent) {
|
|||
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, GetWithRangeCustomizedResponse) {
|
||||
auto res = cli_.Get("/with-range-customized-response", {{make_range_header({{1, 2}})}});
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(StatusCode::BadRequest_400, res->status);
|
||||
EXPECT_EQ(true, res->has_header("Content-Length"));
|
||||
EXPECT_EQ(false, res->has_header("Content-Range"));
|
||||
EXPECT_EQ(JSON_DATA, res->body);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, GetWithRangeMultipartCustomizedResponseMultipleRange) {
|
||||
auto res = cli_.Get("/with-range-customized-response", {{make_range_header({{1, 2}, {4, 5}})}});
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(StatusCode::BadRequest_400, res->status);
|
||||
EXPECT_EQ(true, res->has_header("Content-Length"));
|
||||
EXPECT_EQ(false, res->has_header("Content-Range"));
|
||||
EXPECT_EQ(JSON_DATA, res->body);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, Issue1772) {
|
||||
auto res = cli_.Get("/issue1772", {{make_range_header({{1000, -1}})}});
|
||||
ASSERT_TRUE(res);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue