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'
|
// we expect that rangeStr looks like 'bytes 100-199/200' but some
|
||||||
// but some server returns '100-199/100', omitting bytes-unit specifier
|
// server returns '100-199/200', omitting bytes-unit specifier
|
||||||
// 'bytes'.
|
// 'bytes'. Moreover, some server may return like
|
||||||
|
// 'bytes=100-199/200'.
|
||||||
auto byteRangeSpec = std::find(rangeStr.begin(), rangeStr.end(), ' ');
|
auto byteRangeSpec = std::find(rangeStr.begin(), rangeStr.end(), ' ');
|
||||||
if(byteRangeSpec == rangeStr.end()) {
|
if(byteRangeSpec == rangeStr.end()) {
|
||||||
// we assume bytes-unit specifier omitted.
|
// check for 'bytes=100-199/200' case
|
||||||
byteRangeSpec = rangeStr.begin();
|
byteRangeSpec = std::find(rangeStr.begin(), rangeStr.end(), '=');
|
||||||
|
if (byteRangeSpec == rangeStr.end()) {
|
||||||
|
// we assume bytes-unit specifier omitted.
|
||||||
|
byteRangeSpec = rangeStr.begin();
|
||||||
|
} else {
|
||||||
|
++byteRangeSpec;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
while(byteRangeSpec != rangeStr.end() &&
|
while(byteRangeSpec != rangeStr.end() &&
|
||||||
(*byteRangeSpec == ' ' || *byteRangeSpec == '\t')) {
|
(*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.endByte);
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)0, range.entityLength);
|
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 httpHeader;
|
||||||
httpHeader.put(HttpHeader::CONTENT_RANGE, "bytes 0-/3");
|
httpHeader.put(HttpHeader::CONTENT_RANGE, "bytes 0-/3");
|
||||||
|
|
Loading…
Reference in New Issue