diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index ee286194..3bb5df1f 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -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)); } diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 2d355a64..963dc6fc 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -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_; diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index 6a2a6aff..f393125f 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -115,7 +115,9 @@ createHttpRequest(const SharedHandle& 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 = *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