@@ -3992,6 +3992,14 @@ TEST_F(ServerTest, GetStreamedWithRangeMultipart) {
39923992 EXPECT_EQ (" 267" , res->get_header_value (" Content-Length" ));
39933993 EXPECT_EQ (false , res->has_header (" Content-Range" ));
39943994 EXPECT_EQ (267U , res->body .size ());
3995+
3996+ // Check that both range contents are present
3997+ EXPECT_TRUE (res->body .find (" bc\r\n " ) != std::string::npos);
3998+ EXPECT_TRUE (res->body .find (" ef\r\n " ) != std::string::npos);
3999+
4000+ // Check that Content-Range headers are present for both ranges
4001+ EXPECT_TRUE (res->body .find (" Content-Range: bytes 1-2/7" ) != std::string::npos);
4002+ EXPECT_TRUE (res->body .find (" Content-Range: bytes 4-5/7" ) != std::string::npos);
39954003}
39964004
39974005TEST_F (ServerTest, GetStreamedWithTooManyRanges) {
@@ -4009,14 +4017,56 @@ TEST_F(ServerTest, GetStreamedWithTooManyRanges) {
40094017 EXPECT_EQ (0U , res->body .size ());
40104018}
40114019
4020+ TEST_F (ServerTest, GetStreamedWithOverwrapping) {
4021+ auto res = cli_.Get (" /streamed-with-range" ,
4022+ {{make_range_header ({{1 , 4 }, {2 , 5 }})}});
4023+ ASSERT_TRUE (res);
4024+ EXPECT_EQ (StatusCode::PartialContent_206, res->status );
4025+ EXPECT_EQ (5U , res->body .size ());
4026+
4027+ // Check that overlapping ranges are coalesced into a single range
4028+ EXPECT_EQ (" bcdef" , res->body );
4029+ EXPECT_EQ (" bytes 1-5/7" , res->get_header_value (" Content-Range" ));
4030+
4031+ // Should be single range, not multipart
4032+ EXPECT_TRUE (res->has_header (" Content-Range" ));
4033+ EXPECT_EQ (" text/plain" , res->get_header_value (" Content-Type" ));
4034+ }
4035+
40124036TEST_F (ServerTest, GetStreamedWithNonAscendingRanges) {
4013- auto res = cli_.Get (" /streamed-with-range?error " ,
4014- {{make_range_header ({{0 , - 1 }, {0 , - 1 }})}});
4037+ auto res = cli_.Get (" /streamed-with-range" ,
4038+ {{make_range_header ({{4 , 5 }, {0 , 2 }})}});
40154039 ASSERT_TRUE (res);
4016- EXPECT_EQ (StatusCode::RangeNotSatisfiable_416, res->status );
4017- EXPECT_EQ (" 0" , res->get_header_value (" Content-Length" ));
4018- EXPECT_EQ (false , res->has_header (" Content-Range" ));
4019- EXPECT_EQ (0U , res->body .size ());
4040+ EXPECT_EQ (StatusCode::PartialContent_206, res->status );
4041+ EXPECT_EQ (268U , res->body .size ());
4042+
4043+ // Check that both range contents are present
4044+ EXPECT_TRUE (res->body .find (" ef\r\n " ) != std::string::npos);
4045+ EXPECT_TRUE (res->body .find (" abc\r\n " ) != std::string::npos);
4046+
4047+ // Check that Content-Range headers are present for both ranges
4048+ EXPECT_TRUE (res->body .find (" Content-Range: bytes 4-5/7" ) != std::string::npos);
4049+ EXPECT_TRUE (res->body .find (" Content-Range: bytes 0-2/7" ) != std::string::npos);
4050+ }
4051+
4052+ TEST_F (ServerTest, GetStreamedWithDuplicateRanges) {
4053+ auto res = cli_.Get (" /streamed-with-range" ,
4054+ {{make_range_header ({{0 , 2 }, {0 , 2 }})}});
4055+ ASSERT_TRUE (res);
4056+ EXPECT_EQ (StatusCode::PartialContent_206, res->status );
4057+ EXPECT_EQ (269U , res->body .size ());
4058+
4059+ // Check that both duplicate range contents are present
4060+ size_t first_abc = res->body .find (" abc\r\n " );
4061+ EXPECT_TRUE (first_abc != std::string::npos);
4062+ size_t second_abc = res->body .find (" abc\r\n " , first_abc + 1 );
4063+ EXPECT_TRUE (second_abc != std::string::npos);
4064+
4065+ // Check that Content-Range headers are present for both ranges
4066+ size_t first_range = res->body .find (" Content-Range: bytes 0-2/7" );
4067+ EXPECT_TRUE (first_range != std::string::npos);
4068+ size_t second_range = res->body .find (" Content-Range: bytes 0-2/7" , first_range + 1 );
4069+ EXPECT_TRUE (second_range != std::string::npos);
40204070}
40214071
40224072TEST_F (ServerTest, GetStreamedWithRangesMoreThanTwoOverwrapping) {
@@ -4122,6 +4172,19 @@ TEST_F(ServerTest, GetWithRange4) {
41224172 EXPECT_EQ (std::string (" fg" ), res->body );
41234173}
41244174
4175+ TEST_F (ServerTest, GetWithRange5) {
4176+ auto res = cli_.Get (" /with-range" , {
4177+ make_range_header ({{0 , 5 }}),
4178+ {" Accept-Encoding" , " " },
4179+ });
4180+ ASSERT_TRUE (res);
4181+ EXPECT_EQ (StatusCode::PartialContent_206, res->status );
4182+ EXPECT_EQ (" 6" , res->get_header_value (" Content-Length" ));
4183+ EXPECT_EQ (true , res->has_header (" Content-Range" ));
4184+ EXPECT_EQ (" bytes 0-5/7" , res->get_header_value (" Content-Range" ));
4185+ EXPECT_EQ (std::string (" abcdef" ), res->body );
4186+ }
4187+
41254188TEST_F (ServerTest, GetWithRangeOffsetGreaterThanContent) {
41264189 auto res = cli_.Get (" /with-range" , {{make_range_header ({{10000 , 20000 }})}});
41274190 ASSERT_TRUE (res);
0 commit comments