mirror of https://github.com/aria2/aria2
parent
8709015024
commit
8512fe992e
|
@ -113,13 +113,20 @@ Range HttpHeader::getRange() const
|
|||
}
|
||||
}
|
||||
}
|
||||
// we expect that rangeStr looks like 'bytes 100-199/100'
|
||||
// but some server returns '100-199/100', omitting bytes-unit specifier
|
||||
// 'bytes'.
|
||||
// we expect that rangeStr looks like 'bytes 100-199/200' but some
|
||||
// server returns '100-199/200', omitting bytes-unit specifier
|
||||
// 'bytes'. Moreover, some server may return like
|
||||
// 'bytes=100-199/200'.
|
||||
auto byteRangeSpec = std::find(rangeStr.begin(), rangeStr.end(), ' ');
|
||||
if(byteRangeSpec == rangeStr.end()) {
|
||||
// we assume bytes-unit specifier omitted.
|
||||
byteRangeSpec = rangeStr.begin();
|
||||
// check for 'bytes=100-199/200' case
|
||||
byteRangeSpec = std::find(rangeStr.begin(), rangeStr.end(), '=');
|
||||
if (byteRangeSpec == rangeStr.end()) {
|
||||
// we assume bytes-unit specifier omitted.
|
||||
byteRangeSpec = rangeStr.begin();
|
||||
} else {
|
||||
++byteRangeSpec;
|
||||
}
|
||||
} else {
|
||||
while(byteRangeSpec != rangeStr.end() &&
|
||||
(*byteRangeSpec == ' ' || *byteRangeSpec == '\t')) {
|
||||
|
|
|
@ -101,6 +101,17 @@ void HttpHeaderTest::testGetRange()
|
|||
CPPUNIT_ASSERT_EQUAL((int64_t)0, range.endByte);
|
||||
CPPUNIT_ASSERT_EQUAL((int64_t)0, range.entityLength);
|
||||
}
|
||||
{
|
||||
// Support for non-compliant server
|
||||
HttpHeader httpHeader;
|
||||
httpHeader.put(HttpHeader::CONTENT_RANGE, "bytes=0-1023/1024");
|
||||
|
||||
Range range = httpHeader.getRange();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((int64_t)0, range.startByte);
|
||||
CPPUNIT_ASSERT_EQUAL((int64_t)1023, range.endByte);
|
||||
CPPUNIT_ASSERT_EQUAL((int64_t)1024, range.entityLength);
|
||||
}
|
||||
{
|
||||
HttpHeader httpHeader;
|
||||
httpHeader.put(HttpHeader::CONTENT_RANGE, "bytes 0-/3");
|
||||
|
|
Loading…
Reference in New Issue