mirror of https://github.com/aria2/aria2
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
parent
73f4db883c
commit
b782a56b1c
|
@ -96,6 +96,8 @@ int64_t HttpRequest::getEndByte() const
|
||||||
int64_t endByte =
|
int64_t endByte =
|
||||||
fileEntry_->gtoloff(segment_->getPosition()+segment_->getLength()-1);
|
fileEntry_->gtoloff(segment_->getPosition()+segment_->getLength()-1);
|
||||||
return std::min(endByte, fileEntry_->getLength()-1);
|
return std::min(endByte, fileEntry_->getLength()-1);
|
||||||
|
} else if(endOffsetOverride_ > 0) {
|
||||||
|
return endOffsetOverride_ - 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -201,9 +203,9 @@ std::string HttpRequest::createRequest()
|
||||||
std::string rangeHeader(fmt("bytes=%" PRId64 "-", getStartByte()));
|
std::string rangeHeader(fmt("bytes=%" PRId64 "-", getStartByte()));
|
||||||
if(request_->isPipeliningEnabled()) {
|
if(request_->isPipeliningEnabled()) {
|
||||||
rangeHeader += util::itos(getEndByte());
|
rangeHeader += util::itos(getEndByte());
|
||||||
} else if(getProtocol() != "ftp" && endOffsetOverride_ > 0) {
|
} else if(getEndByte() > 0) {
|
||||||
// FTP via http proxy does not support endbytes
|
// 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));
|
builtinHds.push_back(std::make_pair("Range:", rangeHeader));
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,13 @@ private:
|
||||||
|
|
||||||
bool acceptGzip_;
|
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_;
|
int64_t endOffsetOverride_;
|
||||||
|
|
||||||
std::string ifModSinceHeader_;
|
std::string ifModSinceHeader_;
|
||||||
|
|
|
@ -115,7 +115,9 @@ createHttpRequest(const SharedHandle<Request>& req,
|
||||||
} else {
|
} else {
|
||||||
httpRequest->disableNoCache();
|
httpRequest->disableNoCache();
|
||||||
}
|
}
|
||||||
|
if(endOffset > 0) {
|
||||||
httpRequest->setEndOffsetOverride(endOffset);
|
httpRequest->setEndOffsetOverride(endOffset);
|
||||||
|
}
|
||||||
return httpRequest;
|
return httpRequest;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -181,7 +183,9 @@ bool HttpRequestCommand::executeInternal() {
|
||||||
const SharedHandle<Segment>& segment = *itr;
|
const SharedHandle<Segment>& segment = *itr;
|
||||||
if(!httpConnection_->isIssued(segment)) {
|
if(!httpConnection_->isIssued(segment)) {
|
||||||
int64_t endOffset = 0;
|
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 =
|
size_t nextIndex =
|
||||||
getPieceStorage()->getNextUsedIndex(segment->getIndex());
|
getPieceStorage()->getNextUsedIndex(segment->getIndex());
|
||||||
endOffset = std::min
|
endOffset = std::min
|
||||||
|
|
Loading…
Reference in New Issue