summaryrefslogtreecommitdiff
path: root/src/HttpHeader.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-03-15 15:07:18 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-03-15 15:07:18 +0000
commit11907c175d9e3e6f4069df79dade320b6f93cd7f (patch)
treed866782e0cc2a2eafd48ae3ac2612c280cdd6daa /src/HttpHeader.cc
parentba7f9f765794bc197750253f07211c66afdd69e5 (diff)
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle: * src/AbstractCommand.cc (execute): Rewritten. * src/SegmentMan.h: Segment -> SegmentHandle Introducded HttpResponse class, HttpRequest class to improve code extensiveness and make it clear: * src/HttpDownloadCommand.cc: transfer encoders are now managed by HttpResponse class. * src/HttpRequest.h, src/HttpRequest.cc: New class. * src/HttpResponse.h, src/HttpResponse.cc: New class. * src/HttpConnection.cc: Contruction of http request were moved to HttpRequest class. * src/HttpResponseCommand.h, src/HttpResponseCommand.cc: Refactored. * src/HttpRequestCommand.cc (executeInternal): Rewritten. * src/HttpAuthConfig.h: New class. * src/Range.h: New class. To make FtpTunnel{Request, Response}Command and HttpProxy{Request, Response}Command derived from AbstractProxy{Request, Response}Command: * src/FtpTunnelResponseCommand.h, src/FtpTunnelResponseCommand.cc: Derived from AbstractProxyRequestCommand class. * src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc: Derived from AbstractProxyResponseCommand class. * src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc: Derived from AbstractProxyRequestCommand class. * src/HttpProxyResponseCommand.h, src/HttpProxyResponseCommand.cc: Derived from AbstractProxyResponseCommand class. * src/AbstractProxyRequestCommand.h, src/AbstractProxyRequestCommand.cc : New class. * src/AbstractProxyResponseCommand.h, src/AbstractProxyResponseCommand.cc: New class. To add netrc support: * src/Netrc.h, src/Netrc.cc: New class. * src/Util.h, src/Util.cc (split): New function. * src/HttpHeader.cc (getRange): Fixed so that it inspects "Content-Range" header instead of "Range" header. * src/HttpHeader.h (getStatus): Removed. (setStatus): Removed. * src/Segment.h (getPositionToWrite): New function.
Diffstat (limited to 'src/HttpHeader.cc')
-rw-r--r--src/HttpHeader.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc
index adf74ae3..9cf6b002 100644
--- a/src/HttpHeader.cc
+++ b/src/HttpHeader.cc
@@ -70,26 +70,34 @@ long long int HttpHeader::getFirstAsLLInt(const string& name) const {
if(value == "") {
return 0;
} else {
- return strtoll(value.c_str(), NULL, 10);
+ return strtoll(value.c_str(), 0, 10);
}
}
RangeHandle HttpHeader::getRange() const
{
- string rangeStr = getFirst("Range");
+ string rangeStr = getFirst("Content-Range");
if(rangeStr == "") {
- return 0;
+ string contentLengthStr = getFirst("Content-Length");
+ if(contentLengthStr == "") {
+ return new Range(0, 0, 0);
+ } else {
+ int64_t contentLength = strtoll(contentLengthStr.c_str(), 0, 10);
+ return new Range(0, contentLength-1, contentLength);
+ }
+ }
+ string::size_type rangeSpecIndex = rangeStr.find("bytes ");
+ if(rangeSpecIndex == string::npos) {
+ return new Range(0, 0, 0);
}
pair<string, string> rangePair;
- Util::split(rangePair, rangeStr, '/');
+ Util::split(rangePair, rangeStr.substr(rangeSpecIndex+6), '/');
pair<string, string> startEndBytePair;
Util::split(startEndBytePair, rangePair.first, '-');
int64_t startByte = STRTOLL(startEndBytePair.first.c_str());
int64_t endByte = STRTOLL(startEndBytePair.second.c_str());
- int64_t contentLength = STRTOLL(rangePair.second.c_str());
-
- RangeHandle range = new Range(startByte, endByte, contentLength);
+ int64_t entityLength = STRTOLL(rangePair.second.c_str());
- return range;
+ return new Range(startByte, endByte, entityLength);
}