summaryrefslogtreecommitdiff
path: root/methods/basehttp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'methods/basehttp.cc')
-rw-r--r--methods/basehttp.cc39
1 files changed, 21 insertions, 18 deletions
diff --git a/methods/basehttp.cc b/methods/basehttp.cc
index d7d9bccd0..c3d570c83 100644
--- a/methods/basehttp.cc
+++ b/methods/basehttp.cc
@@ -15,6 +15,11 @@
#include <apt-pkg/fileutl.h>
#include <apt-pkg/strutl.h>
+#include <iostream>
+#include <limits>
+#include <map>
+#include <string>
+#include <vector>
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
@@ -23,11 +28,6 @@
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
-#include <iostream>
-#include <limits>
-#include <map>
-#include <string>
-#include <vector>
#include "basehttp.h"
@@ -146,6 +146,9 @@ bool RequestState::HeaderLine(string const &Line) /*{{{*/
if (stringcasecmp(Tag,"Content-Length:") == 0)
{
+ auto ContentLength = strtoull(Val.c_str(), NULL, 10);
+ if (ContentLength == 0)
+ return true;
if (Encoding == Closes)
Encoding = Stream;
HaveContent = true;
@@ -154,7 +157,7 @@ bool RequestState::HeaderLine(string const &Line) /*{{{*/
if (Result == 416 || (Result >= 300 && Result < 400))
DownloadSizePtr = &JunkSize;
- *DownloadSizePtr = strtoull(Val.c_str(), NULL, 10);
+ *DownloadSizePtr = ContentLength;
if (*DownloadSizePtr >= std::numeric_limits<unsigned long long>::max())
return _error->Errno("HeaderLine", _("The HTTP server sent an invalid Content-Length header"));
else if (*DownloadSizePtr == 0)
@@ -286,18 +289,18 @@ BaseHttpMethod::DealWithHeaders(FetchResult &Res, RequestState &Req)
return IMS_HIT;
}
- /* Redirect
- *
- * Note that it is only OK for us to treat all redirection the same
- * because we *always* use GET, not other HTTP methods. There are
- * three redirection codes for which it is not appropriate that we
- * redirect. Pass on those codes so the error handling kicks in.
- */
- if (AllowRedirect
- && (Req.Result > 300 && Req.Result < 400)
- && (Req.Result != 300 // Multiple Choices
- && Req.Result != 304 // Not Modified
- && Req.Result != 306)) // (Not part of HTTP/1.1, reserved)
+ /* Note that it is only OK for us to treat all redirection the same
+ because we *always* use GET, not other HTTP methods.
+ Codes not mentioned are handled as errors later as required by the
+ HTTP spec to handle unknown codes the same as the x00 code. */
+ constexpr unsigned int RedirectCodes[] = {
+ 301, // Moved Permanently
+ 302, // Found
+ 303, // See Other
+ 307, // Temporary Redirect
+ 308, // Permanent Redirect
+ };
+ if (AllowRedirect && std::find(std::begin(RedirectCodes), std::end(RedirectCodes), Req.Result) != std::end(RedirectCodes))
{
if (Req.Location.empty() == true)
;