@@ -3992,6 +3992,16 @@ 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" ) !=
4002+ std::string::npos);
4003+ EXPECT_TRUE (res->body .find (" Content-Range: bytes 4-5/7" ) !=
4004+ std::string::npos);
39954005}
39964006
39974007TEST_F (ServerTest, GetStreamedWithTooManyRanges) {
@@ -4009,14 +4019,59 @@ TEST_F(ServerTest, GetStreamedWithTooManyRanges) {
40094019 EXPECT_EQ (0U , res->body .size ());
40104020}
40114021
4022+ TEST_F (ServerTest, GetStreamedWithOverwrapping) {
4023+ auto res =
4024+ cli_.Get (" /streamed-with-range" , {{make_range_header ({{1 , 4 }, {2 , 5 }})}});
4025+ ASSERT_TRUE (res);
4026+ EXPECT_EQ (StatusCode::PartialContent_206, res->status );
4027+ EXPECT_EQ (5U , res->body .size ());
4028+
4029+ // Check that overlapping ranges are coalesced into a single range
4030+ EXPECT_EQ (" bcdef" , res->body );
4031+ EXPECT_EQ (" bytes 1-5/7" , res->get_header_value (" Content-Range" ));
4032+
4033+ // Should be single range, not multipart
4034+ EXPECT_TRUE (res->has_header (" Content-Range" ));
4035+ EXPECT_EQ (" text/plain" , res->get_header_value (" Content-Type" ));
4036+ }
4037+
40124038TEST_F (ServerTest, GetStreamedWithNonAscendingRanges) {
4013- auto res = cli_. Get ( " /streamed-with-range?error " ,
4014- {{make_range_header ({{0 , - 1 }, {0 , - 1 }})}});
4039+ auto res =
4040+ cli_. Get ( " /streamed-with-range " , {{make_range_header ({{4 , 5 }, {0 , 2 }})}});
40154041 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 ());
4042+ EXPECT_EQ (StatusCode::PartialContent_206, res->status );
4043+ EXPECT_EQ (268U , res->body .size ());
4044+
4045+ // Check that both range contents are present
4046+ EXPECT_TRUE (res->body .find (" ef\r\n " ) != std::string::npos);
4047+ EXPECT_TRUE (res->body .find (" abc\r\n " ) != std::string::npos);
4048+
4049+ // Check that Content-Range headers are present for both ranges
4050+ EXPECT_TRUE (res->body .find (" Content-Range: bytes 4-5/7" ) !=
4051+ std::string::npos);
4052+ EXPECT_TRUE (res->body .find (" Content-Range: bytes 0-2/7" ) !=
4053+ std::string::npos);
4054+ }
4055+
4056+ TEST_F (ServerTest, GetStreamedWithDuplicateRanges) {
4057+ auto res =
4058+ cli_.Get (" /streamed-with-range" , {{make_range_header ({{0 , 2 }, {0 , 2 }})}});
4059+ ASSERT_TRUE (res);
4060+ EXPECT_EQ (StatusCode::PartialContent_206, res->status );
4061+ EXPECT_EQ (269U , res->body .size ());
4062+
4063+ // Check that both duplicate range contents are present
4064+ size_t first_abc = res->body .find (" abc\r\n " );
4065+ EXPECT_TRUE (first_abc != std::string::npos);
4066+ size_t second_abc = res->body .find (" abc\r\n " , first_abc + 1 );
4067+ EXPECT_TRUE (second_abc != std::string::npos);
4068+
4069+ // Check that Content-Range headers are present for both ranges
4070+ size_t first_range = res->body .find (" Content-Range: bytes 0-2/7" );
4071+ EXPECT_TRUE (first_range != std::string::npos);
4072+ size_t second_range =
4073+ res->body .find (" Content-Range: bytes 0-2/7" , first_range + 1 );
4074+ EXPECT_TRUE (second_range != std::string::npos);
40204075}
40214076
40224077TEST_F (ServerTest, GetStreamedWithRangesMoreThanTwoOverwrapping) {
@@ -4122,6 +4177,19 @@ TEST_F(ServerTest, GetWithRange4) {
41224177 EXPECT_EQ (std::string (" fg" ), res->body );
41234178}
41244179
4180+ TEST_F (ServerTest, GetWithRange5) {
4181+ auto res = cli_.Get (" /with-range" , {
4182+ make_range_header ({{0 , 5 }}),
4183+ {" Accept-Encoding" , " " },
4184+ });
4185+ ASSERT_TRUE (res);
4186+ EXPECT_EQ (StatusCode::PartialContent_206, res->status );
4187+ EXPECT_EQ (" 6" , res->get_header_value (" Content-Length" ));
4188+ EXPECT_EQ (true , res->has_header (" Content-Range" ));
4189+ EXPECT_EQ (" bytes 0-5/7" , res->get_header_value (" Content-Range" ));
4190+ EXPECT_EQ (std::string (" abcdef" ), res->body );
4191+ }
4192+
41254193TEST_F (ServerTest, GetWithRangeOffsetGreaterThanContent) {
41264194 auto res = cli_.Get (" /with-range" , {{make_range_header ({{10000 , 20000 }})}});
41274195 ASSERT_TRUE (res);
0 commit comments