1
0
mirror of synced 2025-04-20 11:47:43 +03:00

Fix suffix-byte-range issue (#711)

This commit is contained in:
Omkar Jadhav 2020-10-20 20:41:27 +05:30 committed by GitHub
parent 4bb001351c
commit bc4a613b6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -173,6 +173,7 @@ using socket_t = int;
#define INVALID_SOCKET (-1)
#endif //_WIN32
#include <algorithm>
#include <array>
#include <atomic>
#include <cassert>
@ -3153,7 +3154,7 @@ get_range_offset_and_length(const Request &req, size_t content_length,
auto slen = static_cast<ssize_t>(content_length);
if (r.first == -1) {
r.first = slen - r.second;
r.first = std::max(static_cast<ssize_t>(0), slen - r.second);
r.second = slen - 1;
}

View File

@ -1897,6 +1897,30 @@ TEST_F(ServerTest, GetStreamedWithRange2) {
EXPECT_EQ(std::string("bcdefg"), res->body);
}
TEST_F(ServerTest, GetStreamedWithRangeSuffix1) {
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"));
EXPECT_EQ(true, res->has_header("Content-Range"));
EXPECT_EQ(std::string("efg"), res->body);
}
TEST_F(ServerTest, GetStreamedWithRangeSuffix2) {
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"));
EXPECT_EQ(true, res->has_header("Content-Range"));
EXPECT_EQ(std::string("abcdefg"), res->body);
}
TEST_F(ServerTest, GetStreamedWithRangeError) {
auto res = cli_.Get("/streamed-with-range", {
{"Range", "bytes=92233720368547758079223372036854775806-92233720368547758079223372036854775807"}