2008-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Suppress content-range error when 'Content-Range' response header
	doesn't contains bytes-unit specifier 'bytes'
	* src/HttpHeader.cc (getRange)
	* test/HttpHeaderTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-03-15 04:25:55 +00:00
parent 538a8fcfe7
commit 42fa16b780
3 changed files with 48 additions and 16 deletions

View File

@ -1,3 +1,10 @@
2008-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Suppress content-range error when 'Content-Range' response header
doesn't contains bytes-unit specifier 'bytes'
* src/HttpHeader.cc (getRange)
* test/HttpHeaderTest.cc
2008-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed compilation error with g++-4.3

View File

@ -93,18 +93,29 @@ RangeHandle HttpHeader::getRange() const
}
}
}
std::string::size_type rangeSpecIndex = rangeStr.find("bytes ");
if(rangeSpecIndex == std::string::npos) {
return new Range(0, 0, 0);
std::string byteRangeSpec;
{
// we expect that rangeStr looks like 'bytes 100-199/100'
// but some server returns '100-199/100', omitting bytes-unit sepcifier
// 'bytes'.
std::pair<std::string, std::string> splist;
Util::split(splist, rangeStr, ' ');
if(splist.second.empty()) {
// we assume bytes-unit specifier omitted.
byteRangeSpec = splist.first;
} else {
byteRangeSpec = splist.second;
}
}
std::pair<std::string, std::string> rangePair;
Util::split(rangePair, rangeStr.substr(rangeSpecIndex+6), '/');
std::pair<std::string, std::string> startEndBytePair;
Util::split(startEndBytePair, rangePair.first, '-');
std::pair<std::string, std::string> byteRangeSpecPair;
Util::split(byteRangeSpecPair, byteRangeSpec, '/');
off_t startByte = Util::parseLLInt(startEndBytePair.first);
off_t endByte = Util::parseLLInt(startEndBytePair.second);
uint64_t entityLength = Util::parseULLInt(rangePair.second);
std::pair<std::string, std::string> byteRangeRespSpecPair;
Util::split(byteRangeRespSpecPair, byteRangeSpecPair.first, '-');
off_t startByte = Util::parseLLInt(byteRangeRespSpecPair.first);
off_t endByte = Util::parseLLInt(byteRangeRespSpecPair.second);
uint64_t entityLength = Util::parseULLInt(byteRangeSpecPair.second);
return new Range(startByte, endByte, entityLength);
}

View File

@ -20,14 +20,28 @@ CPPUNIT_TEST_SUITE_REGISTRATION( HttpHeaderTest );
void HttpHeaderTest::testGetRange()
{
HttpHeader httpHeader;
httpHeader.put("Content-Range", "bytes 1-499/1234");
{
HttpHeader httpHeader;
httpHeader.put("Content-Range",
"9223372036854775800-9223372036854775801/9223372036854775807");
SharedHandle<Range> range = httpHeader.getRange();
SharedHandle<Range> range = httpHeader.getRange();
CPPUNIT_ASSERT_EQUAL(9223372036854775800LL, range->getStartByte());
CPPUNIT_ASSERT_EQUAL(9223372036854775801LL, range->getEndByte());
CPPUNIT_ASSERT_EQUAL(9223372036854775807ULL, range->getEntityLength());
}
{
HttpHeader httpHeader;
httpHeader.put("Content-Range",
"9223372036854775800-9223372036854775801/9223372036854775807");
SharedHandle<Range> range = httpHeader.getRange();
CPPUNIT_ASSERT_EQUAL(1LL, range->getStartByte());
CPPUNIT_ASSERT_EQUAL(499LL, range->getEndByte());
CPPUNIT_ASSERT_EQUAL(1234ULL, range->getEntityLength());
CPPUNIT_ASSERT_EQUAL(9223372036854775800LL, range->getStartByte());
CPPUNIT_ASSERT_EQUAL(9223372036854775801LL, range->getEndByte());
CPPUNIT_ASSERT_EQUAL(9223372036854775807ULL, range->getEntityLength());
}
}
} // namespace aria2