|
|
@@ -90,18 +90,30 @@ RangeHandle HttpHeader::getRange() const
|
|
|
return new Range(0, contentLength-1, contentLength);
|
|
|
}
|
|
|
}
|
|
|
- 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, '/');
|
|
|
+
|
|
|
+ std::pair<std::string, std::string> byteRangeRespSpecPair;
|
|
|
+ Util::split(byteRangeRespSpecPair, byteRangeSpecPair.first, '-');
|
|
|
|
|
|
- int64_t startByte = STRTOLL(startEndBytePair.first.c_str());
|
|
|
- int64_t endByte = STRTOLL(startEndBytePair.second.c_str());
|
|
|
- int64_t entityLength = STRTOLL(rangePair.second.c_str());
|
|
|
+ int64_t startByte = STRTOLL(byteRangeRespSpecPair.first.c_str());
|
|
|
+ int64_t endByte = STRTOLL(byteRangeRespSpecPair.second.c_str());
|
|
|
+ int64_t entityLength = STRTOLL(byteRangeSpecPair.second.c_str());
|
|
|
|
|
|
return new Range(startByte, endByte, entityLength);
|
|
|
}
|