Treat 30X response without Location header field as error

This is required to make segmented download work.
This commit is contained in:
Tatsuhiro Tsujikawa 2014-02-05 21:20:09 +09:00
parent ec4b729704
commit b18e62dba7
3 changed files with 16 additions and 6 deletions

View File

@ -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) {

View File

@ -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));
}

View File

@ -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);