diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-12-07 22:57:34 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-12-09 21:39:43 +0900 |
| commit | 12988e5282ef52a2806cbaca9f4074698f35e399 (patch) | |
| tree | 7a8d5a65a8e8478ba5855e84a1077baee1a2028d /src/HttpHeader.cc | |
| parent | f25e67b0178511b26d55642f215a095321a169a8 (diff) | |
Replaced uint64_t with off_t or int64_t.
Since off_t is int64_t with LFS, we cannot take advantage of extra
capacity of uint64_t.
Diffstat (limited to 'src/HttpHeader.cc')
| -rw-r--r-- | src/HttpHeader.cc | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index ad926cc0..ff6aa8d9 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -108,16 +108,23 @@ HttpHeader::equalRange(const std::string& name) const return table_.equal_range(name); } -unsigned int HttpHeader::findAsUInt(const std::string& name) const { - return findAsULLInt(name); +int32_t HttpHeader::findAsInt(const std::string& name) const +{ + const std::string& value = find(name); + if(value.empty()) { + return 0; + } else { + return util::parseInt(value); + } } -uint64_t HttpHeader::findAsULLInt(const std::string& name) const { +int64_t HttpHeader::findAsLLInt(const std::string& name) const +{ const std::string& value = find(name); if(value.empty()) { return 0; } else { - return util::parseULLInt(value); + return util::parseLLInt(value); } } @@ -129,7 +136,10 @@ RangeHandle HttpHeader::getRange() const if(clenStr.empty()) { return SharedHandle<Range>(new Range()); } else { - uint64_t contentLength = util::parseULLInt(clenStr); + off_t contentLength = util::parseLLInt(clenStr); + if(contentLength < 0) { + throw DL_ABORT_EX("Content-Length must be positive"); + } if(contentLength == 0) { return SharedHandle<Range>(new Range()); } else { @@ -168,8 +178,11 @@ RangeHandle HttpHeader::getRange() const } off_t startByte = util::parseLLInt(std::string(byteRangeSpec, minus)); off_t endByte = util::parseLLInt(std::string(minus+1, slash)); - uint64_t entityLength = - util::parseULLInt(std::string(slash+1, rangeStr.end())); + off_t entityLength = + util::parseLLInt(std::string(slash+1, rangeStr.end())); + if(startByte < 0 || endByte < 0 || entityLength < 0) { + throw DL_ABORT_EX("byte-range-spec must be positive"); + } return SharedHandle<Range>(new Range(startByte, endByte, entityLength)); } |
