mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 09:18:27 +00:00
Fix problem with invalid range
This commit is contained in:
parent
401de608df
commit
041122908c
2 changed files with 171 additions and 146 deletions
45
test/test.cc
45
test/test.cc
|
@ -1899,9 +1899,7 @@ TEST_F(ServerTest, GetStreamedWithRange2) {
|
|||
}
|
||||
|
||||
TEST_F(ServerTest, GetStreamedWithRangeSuffix1) {
|
||||
auto res = cli_.Get("/streamed-with-range", {
|
||||
{"Range", "bytes=-3"}
|
||||
});
|
||||
auto res = cli_.Get("/streamed-with-range", {{"Range", "bytes=-3"}});
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(206, res->status);
|
||||
EXPECT_EQ("3", res->get_header_value("Content-Length"));
|
||||
|
@ -1909,11 +1907,8 @@ TEST_F(ServerTest, GetStreamedWithRangeSuffix1) {
|
|||
EXPECT_EQ(std::string("efg"), res->body);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(ServerTest, GetStreamedWithRangeSuffix2) {
|
||||
auto res = cli_.Get("/streamed-with-range", {
|
||||
{"Range", "bytes=-9999"}
|
||||
});
|
||||
auto res = cli_.Get("/streamed-with-range", {{"Range", "bytes=-9999"}});
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(206, res->status);
|
||||
EXPECT_EQ("7", res->get_header_value("Content-Length"));
|
||||
|
@ -1921,18 +1916,17 @@ TEST_F(ServerTest, GetStreamedWithRangeSuffix2) {
|
|||
EXPECT_EQ(std::string("abcdefg"), res->body);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(ServerTest, GetStreamedWithRangeError) {
|
||||
auto res = cli_.Get("/streamed-with-range", {
|
||||
{"Range", "bytes=92233720368547758079223372036854775806-92233720368547758079223372036854775807"}
|
||||
});
|
||||
auto res = cli_.Get("/streamed-with-range",
|
||||
{{"Range", "bytes=92233720368547758079223372036854775806-"
|
||||
"92233720368547758079223372036854775807"}});
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(416, res->status);
|
||||
}
|
||||
|
||||
//Tests long long overflow.
|
||||
TEST_F(ServerTest, GetRangeWithMaxLongLength) {
|
||||
auto res = cli_.Get("/with-range",{{"Range", "bytes=0-9223372036854775807"}});
|
||||
auto res =
|
||||
cli_.Get("/with-range", {{"Range", "bytes=0-9223372036854775807"}});
|
||||
EXPECT_EQ(206, res->status);
|
||||
EXPECT_EQ("7", res->get_header_value("Content-Length"));
|
||||
EXPECT_EQ(true, res->has_header("Content-Range"));
|
||||
|
@ -2020,11 +2014,11 @@ TEST_F(ServerTest, GetWithRange4) {
|
|||
EXPECT_EQ(std::string("fg"), res->body);
|
||||
}
|
||||
|
||||
//TEST_F(ServerTest, GetWithRangeOffsetGreaterThanContent) {
|
||||
// auto res = cli_.Get("/with-range", {{make_range_header({{10000, 20000}})}});
|
||||
// ASSERT_TRUE(res);
|
||||
// EXPECT_EQ(416, res->status);
|
||||
//}
|
||||
TEST_F(ServerTest, GetWithRangeOffsetGreaterThanContent) {
|
||||
auto res = cli_.Get("/with-range", {{make_range_header({{10000, 20000}})}});
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(416, res->status);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, GetWithRangeMultipart) {
|
||||
auto res = cli_.Get("/with-range", {{make_range_header({{1, 2}, {4, 5}})}});
|
||||
|
@ -2035,11 +2029,12 @@ TEST_F(ServerTest, GetWithRangeMultipart) {
|
|||
EXPECT_EQ(269, res->body.size());
|
||||
}
|
||||
|
||||
//TEST_F(ServerTest, GetWithRangeMultipartOffsetGreaterThanContent) {
|
||||
// auto res = cli_.Get("/with-range", {{make_range_header({{-1, 2}, {10000, 30000}})}});
|
||||
// ASSERT_TRUE(res);
|
||||
// EXPECT_EQ(416, res->status);
|
||||
//}
|
||||
TEST_F(ServerTest, GetWithRangeMultipartOffsetGreaterThanContent) {
|
||||
auto res =
|
||||
cli_.Get("/with-range", {{make_range_header({{-1, 2}, {10000, 30000}})}});
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(416, res->status);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, GetStreamedChunked) {
|
||||
auto res = cli_.Get("/streamed-chunked");
|
||||
|
@ -3058,9 +3053,7 @@ TEST(KeepAliveTest, ReadTimeoutSSL) {
|
|||
res.set_content("b", "text/plain");
|
||||
});
|
||||
|
||||
auto listen_thread = std::thread([&svr]() {
|
||||
svr.listen("localhost", PORT);
|
||||
});
|
||||
auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
|
||||
while (!svr.is_running()) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue