Handling of unsatisfiable ranges

This commit is contained in:
Veloman Yunkan 2020-05-26 02:11:26 +04:00
parent 37032892a4
commit c2ebdefe8d
2 changed files with 6 additions and 1 deletions

View File

@ -85,6 +85,9 @@ ByteRange ByteRange::resolve(int64_t contentSize) const
const int64_t resolved_last = std::min(contentSize-1, last()); const int64_t resolved_last = std::min(contentSize-1, last());
if ( resolved_first > resolved_last )
return ByteRange(INVALID, 0, contentSize-1);
return ByteRange(RESOLVED_PARTIAL_CONTENT, resolved_first, resolved_last); return ByteRange(RESOLVED_PARTIAL_CONTENT, resolved_first, resolved_last);
} }

View File

@ -465,7 +465,9 @@ TEST_F(ServerTest, InvalidAndMultiRangeByteRangeRequestsResultIn416Responses)
const char* invalidRanges[] = { const char* invalidRanges[] = {
"0-10", "bytes=", "bytes=123", "bytes=-10-20", "bytes=10-20xxx", "0-10", "bytes=", "bytes=123", "bytes=-10-20", "bytes=10-20xxx",
"bytes=10-0", "bytes=10-20, 30-40" "bytes=10-0", // reversed range
"bytes=10-20, 30-40", // multi-range
"bytes=1000000-", "bytes=30000-30100" // unsatisfiable ranges
}; };
for( const char* range : invalidRanges ) for( const char* range : invalidRanges )