Show correct end byte in error message when HTTP response range is not ok

Previously, unless HTTP pipelining is enabled, end byte in that
message is always 0. With this change, it shows correct end byte sent
to the HTTP server.
pull/46/head
Tatsuhiro Tsujikawa 2013-02-23 15:37:35 +09:00
parent 73f4db883c
commit b782a56b1c
3 changed files with 17 additions and 4 deletions

View File

@ -96,6 +96,8 @@ int64_t HttpRequest::getEndByte() const
int64_t endByte =
fileEntry_->gtoloff(segment_->getPosition()+segment_->getLength()-1);
return std::min(endByte, fileEntry_->getLength()-1);
} else if(endOffsetOverride_ > 0) {
return endOffsetOverride_ - 1;
} else {
return 0;
}
@ -201,9 +203,9 @@ std::string HttpRequest::createRequest()
std::string rangeHeader(fmt("bytes=%" PRId64 "-", getStartByte()));
if(request_->isPipeliningEnabled()) {
rangeHeader += util::itos(getEndByte());
} else if(getProtocol() != "ftp" && endOffsetOverride_ > 0) {
} else if(getEndByte() > 0) {
// FTP via http proxy does not support endbytes
rangeHeader += util::itos(endOffsetOverride_-1);
rangeHeader += util::itos(getEndByte());
}
builtinHds.push_back(std::make_pair("Range:", rangeHeader));
}

View File

@ -88,6 +88,13 @@ private:
bool acceptGzip_;
// Historically, aria2 did not specify end byte marker unless http
// pipelining is enabled. Sometimes end byte is known because the
// segment/piece ahead of this request was already acquired. In this
// case, specifying end byte enables to reuse connection. To achieve
// this, if endOffsetOverride_ is more than 0, its value - 1 is used
// as an end byte. Please note that FTP protocol cannot specify end
// bytes and it is also true if it is used via HTTP proxy.
int64_t endOffsetOverride_;
std::string ifModSinceHeader_;

View File

@ -115,7 +115,9 @@ createHttpRequest(const SharedHandle<Request>& req,
} else {
httpRequest->disableNoCache();
}
httpRequest->setEndOffsetOverride(endOffset);
if(endOffset > 0) {
httpRequest->setEndOffsetOverride(endOffset);
}
return httpRequest;
}
} // namespace
@ -181,7 +183,9 @@ bool HttpRequestCommand::executeInternal() {
const SharedHandle<Segment>& segment = *itr;
if(!httpConnection_->isIssued(segment)) {
int64_t endOffset = 0;
if(getRequestGroup()->getTotalLength() > 0 && getPieceStorage()) {
// FTP via HTTP proxy does not support end byte marker
if(getRequest()->getProtocol() != "ftp" &&
getRequestGroup()->getTotalLength() > 0 && getPieceStorage()) {
size_t nextIndex =
getPieceStorage()->getNextUsedIndex(segment->getIndex());
endOffset = std::min