From f9e2e914996ce8f0af33d5bfed52e814e0f4a861 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 1 Jul 2021 15:35:21 +0200 Subject: basehttp: Turn HaveContent into a TriState We need to be able to set HaveContent to false if the Content-Length is 0, and not have that overriden just because a later header is Content-Type. --- methods/basehttp.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'methods/basehttp.cc') diff --git a/methods/basehttp.cc b/methods/basehttp.cc index f2c4156e1..6d0b334e3 100644 --- a/methods/basehttp.cc +++ b/methods/basehttp.cc @@ -74,7 +74,7 @@ ServerState::RunHeadersResult ServerState::RunHeaders(RequestState &Req, continue; // Tidy up the connection persistence state. - if (Req.Encoding == RequestState::Closes && Req.HaveContent == true) + if (Req.Encoding == RequestState::Closes && Req.haveContent == HaveContent::TRUE) Persistent = false; return RUN_HEADERS_OK; @@ -157,7 +157,7 @@ bool RequestState::HeaderLine(string const &Line) /*{{{*/ return true; if (Encoding == Closes) Encoding = Stream; - HaveContent = true; + haveContent = HaveContent::TRUE; unsigned long long * DownloadSizePtr = &DownloadSize; if (Result == 416 || (Result >= 300 && Result < 400)) @@ -167,7 +167,7 @@ bool RequestState::HeaderLine(string const &Line) /*{{{*/ if (*DownloadSizePtr >= std::numeric_limits::max()) return _error->Errno("HeaderLine", _("The HTTP server sent an invalid Content-Length header")); else if (*DownloadSizePtr == 0) - HaveContent = false; + haveContent = HaveContent::FALSE; // On partial content (206) the Content-Length less than the real // size, so do not set it here but leave that to the Content-Range @@ -180,7 +180,7 @@ bool RequestState::HeaderLine(string const &Line) /*{{{*/ if (stringcasecmp(Tag,"Content-Type:") == 0) { - HaveContent = true; + haveContent = HaveContent::TRUE; return true; } @@ -190,7 +190,7 @@ bool RequestState::HeaderLine(string const &Line) /*{{{*/ // for such responses. if ((Result == 416 || Result == 206) && stringcasecmp(Tag,"Content-Range:") == 0) { - HaveContent = true; + haveContent = HaveContent::TRUE; // ยง14.16 says 'byte-range-resp-spec' should be a '*' in case of 416 if (Result == 416 && sscanf(Val.c_str(), "bytes */%llu",&TotalFileSize) == 1) @@ -207,7 +207,7 @@ bool RequestState::HeaderLine(string const &Line) /*{{{*/ if (stringcasecmp(Tag,"Transfer-Encoding:") == 0) { - HaveContent = true; + haveContent = HaveContent::TRUE; if (stringcasecmp(Val,"chunked") == 0) Encoding = Chunked; return true; @@ -337,7 +337,7 @@ BaseHttpMethod::DealWithHeaders(FetchResult &Res, RequestState &Req) { SetFailReason("RedirectionLoop"); _error->Error("Redirection loop encountered"); - if (Req.HaveContent == true) + if (Req.haveContent == HaveContent::TRUE) return ERROR_WITH_CONTENT_PAGE; return ERROR_UNRECOVERABLE; } @@ -354,7 +354,7 @@ BaseHttpMethod::DealWithHeaders(FetchResult &Res, RequestState &Req) if (tmpURI.Access.find('+') != std::string::npos) { _error->Error("Server tried to trick us into using a specific implementation: %s", tmpURI.Access.c_str()); - if (Req.HaveContent == true) + if (Req.haveContent == HaveContent::TRUE) return ERROR_WITH_CONTENT_PAGE; return ERROR_UNRECOVERABLE; } @@ -380,7 +380,7 @@ BaseHttpMethod::DealWithHeaders(FetchResult &Res, RequestState &Req) { SetFailReason("RedirectionLoop"); _error->Error("Redirection loop encountered"); - if (Req.HaveContent == true) + if (Req.haveContent == HaveContent::TRUE) return ERROR_WITH_CONTENT_PAGE; return ERROR_UNRECOVERABLE; } @@ -433,11 +433,11 @@ BaseHttpMethod::DealWithHeaders(FetchResult &Res, RequestState &Req) if (partialHit == true) { // the file is completely downloaded, but was not moved - if (Req.HaveContent == true) + if (Req.haveContent == HaveContent::TRUE) { // nuke the sent error page Server->RunDataToDevNull(Req); - Req.HaveContent = false; + Req.haveContent = HaveContent::FALSE; } Req.StartPos = Req.TotalFileSize; Req.Result = 200; @@ -461,7 +461,7 @@ BaseHttpMethod::DealWithHeaders(FetchResult &Res, RequestState &Req) SetFailReason(err); _error->Error("%u %s", Req.Result, Req.Code); } - if (Req.HaveContent == true) + if (Req.haveContent == HaveContent::TRUE) return ERROR_WITH_CONTENT_PAGE; return ERROR_UNRECOVERABLE; } @@ -699,7 +699,7 @@ int BaseHttpMethod::Loop() // so instead we use the size of the biggest item in the queue Req.MaximumSize = FindMaximumObjectSizeInQueue(); - if (Req.HaveContent) + if (Req.haveContent == HaveContent::TRUE) { /* If the server provides Content-Length we can figure out with it if this satisfies any request we have made so far (in the pipeline). @@ -861,7 +861,7 @@ int BaseHttpMethod::Loop() case TRY_AGAIN_OR_REDIRECT: { // Clear rest of response if there is content - if (Req.HaveContent) + if (Req.haveContent == HaveContent::TRUE) Server->RunDataToDevNull(Req); Redirect(NextURI); break; -- cgit v1.2.3-70-g09d2