mirror of
https://github.com/aria2/aria2.git
synced 2025-01-08 11:01:38 +00:00
Treat 30X response without Location header field as error
This is required to make segmented download work.
This commit is contained in:
parent
ec4b729704
commit
b18e62dba7
@ -105,6 +105,10 @@ void HttpResponse::validateResponse() const
|
||||
case 303: // See Other
|
||||
case 307: // Temporary Redirect
|
||||
case 308: // Permanent Redirect
|
||||
if (!httpHeader_->defined(HttpHeader::LOCATION)) {
|
||||
throw DL_ABORT_EX2(fmt(EX_LOCATION_HEADER_REQUIRED, statusCode),
|
||||
error_code::HTTP_PROTOCOL_ERROR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (statusCode >= 400) {
|
||||
|
@ -231,11 +231,10 @@ bool HttpResponseCommand::executeInternal()
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
}
|
||||
|
||||
if (statusCode == 404) {
|
||||
grp->increaseAndValidateFileNotFoundCount();
|
||||
return skipResponseBody(std::move(httpResponse));
|
||||
}
|
||||
if (statusCode >= 400 || statusCode == 304 || httpResponse->isRedirect()) {
|
||||
if(statusCode >= 300) {
|
||||
if(statusCode == 404) {
|
||||
grp->increaseAndValidateFileNotFoundCount();
|
||||
}
|
||||
return skipResponseBody(std::move(httpResponse));
|
||||
}
|
||||
|
||||
|
@ -362,7 +362,14 @@ void HttpResponseTest::testValidateResponse()
|
||||
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||
httpResponse.getHttpHeader()->setStatusCode(301);
|
||||
|
||||
// It is fine without Location header
|
||||
try {
|
||||
httpResponse.validateResponse();
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(Exception& e) {
|
||||
// success
|
||||
}
|
||||
|
||||
httpResponse.getHttpHeader()->put(HttpHeader::LOCATION, "http://a/b");
|
||||
httpResponse.validateResponse();
|
||||
|
||||
httpResponse.getHttpHeader()->setStatusCode(201);
|
||||
|
Loading…
Reference in New Issue
Block a user