pull/1869/merge
rkouznetsov 2024-07-04 19:36:10 +01:00 committed by GitHub
commit 6550e9baf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 7 deletions

View File

@ -53,6 +53,7 @@
#include "Request.h"
#include "DownloadHandlerConstants.h"
#include "MessageDigest.h"
#include "LogFactory.h"
namespace aria2 {
@ -124,7 +125,7 @@ bool HttpRequest::isRangeSatisfied(const Range& range) const
return true;
}
return getStartByte() == range.startByte &&
(getEndByte() == 0 || getEndByte() == range.endByte) &&
(getEndByte() == 0 || getEndByte() <= range.endByte) &&
(fileEntry_->getLength() == 0 ||
fileEntry_->getLength() == range.entityLength);
}

View File

@ -78,12 +78,26 @@ void HttpResponse::validateResponse() const
// compare the received range against the requested range
auto responseRange = httpHeader_->getRange();
if (!httpRequest_->isRangeSatisfied(responseRange)) {
throw DL_ABORT_EX2(
fmt(EX_INVALID_RANGE_HEADER, httpRequest_->getStartByte(),
httpRequest_->getEndByte(), httpRequest_->getEntityLength(),
responseRange.startByte, responseRange.endByte,
responseRange.entityLength),
error_code::CANNOT_RESUME);
if ( httpRequest_->getEndByte() > 0 &&
httpRequest_->getEndByte() <= responseRange.endByte){
// Some servers return full length of file as endByte
// regardless of what was requested.
// If server offers more, ignore for a while and hope for the best.
A2_LOG_WARN( fmt(MSG_STRANGE_RANGE_HEADER, cuid_,
httpRequest_->getStartByte(),
httpRequest_->getEndByte(), httpRequest_->getEntityLength(),
responseRange.startByte, responseRange.endByte,
responseRange.entityLength));
} else {
throw DL_ABORT_EX2(
fmt(EX_INVALID_RANGE_HEADER, httpRequest_->getStartByte(),
httpRequest_->getEndByte(), httpRequest_->getEntityLength(),
responseRange.startByte, responseRange.endByte,
responseRange.entityLength),
error_code::CANNOT_RESUME);
}
}
}
return;

View File

@ -211,6 +211,7 @@
#define MSG_REMOVING_UNSELECTED_FILE _("GID#%s - Removing unselected file.")
#define MSG_FILE_REMOVED _("File %s removed.")
#define MSG_FILE_COULD_NOT_REMOVED _("File %s could not be removed.")
#define MSG_STRANGE_RANGE_HEADER "CUID#%" PRId64 " Strange range header. Request: %" PRId64 "-%" PRId64 "/%" PRId64 ", Response: %" PRId64 "-%" PRId64 "/%" PRId64 ""
#define EX_TIME_OUT _("Timeout.")
#define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")