diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2021-07-01 15:35:21 +0200 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2021-07-01 15:35:21 +0200 |
| commit | f9e2e914996ce8f0af33d5bfed52e814e0f4a861 (patch) | |
| tree | 58348187c870592a4a4725a24a74778793905683 /methods | |
| parent | 690f6191a4332123a912c812a19a37cef253e90c (diff) | |
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.
Diffstat (limited to 'methods')
| -rw-r--r-- | methods/basehttp.cc | 28 | ||||
| -rw-r--r-- | methods/basehttp.h | 9 |
2 files changed, 22 insertions, 15 deletions
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<unsigned long long>::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; diff --git a/methods/basehttp.h b/methods/basehttp.h index c0d14d854..2a13c7abf 100644 --- a/methods/basehttp.h +++ b/methods/basehttp.h @@ -27,6 +27,12 @@ class Hashes; class BaseHttpMethod; struct ServerState; +enum class HaveContent +{ + UNKNOWN, + FALSE, + TRUE, +}; struct RequestState { unsigned int Major = 0; @@ -46,7 +52,8 @@ struct RequestState unsigned long long MaximumSize = 0; time_t Date; - bool HaveContent = false; + HaveContent haveContent = HaveContent::UNKNOWN; + enum {Chunked,Stream,Closes} Encoding = Closes; enum {Header, Data} State = Header; std::string Location; |
