فهرست منبع

Treat 30X response without Location header field as error

This is required to make segmented download work.
Tatsuhiro Tsujikawa 11 سال پیش
والد
کامیت
b18e62dba7
3فایلهای تغییر یافته به همراه16 افزوده شده و 6 حذف شده
  1. 4 0
      src/HttpResponse.cc
  2. 4 5
      src/HttpResponseCommand.cc
  3. 8 1
      test/HttpResponseTest.cc

+ 4 - 0
src/HttpResponse.cc

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

+ 4 - 5
src/HttpResponseCommand.cc

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

+ 8 - 1
test/HttpResponseTest.cc

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