diff options
Diffstat (limited to 'src/zenhttp')
| -rw-r--r-- | src/zenhttp/clients/httpclientcommon.cpp | 33 | ||||
| -rw-r--r-- | src/zenhttp/httpclient.cpp | 11 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpclient.h | 4 |
3 files changed, 22 insertions, 26 deletions
diff --git a/src/zenhttp/clients/httpclientcommon.cpp b/src/zenhttp/clients/httpclientcommon.cpp index 248ae9d70..9ded23375 100644 --- a/src/zenhttp/clients/httpclientcommon.cpp +++ b/src/zenhttp/clients/httpclientcommon.cpp @@ -394,31 +394,28 @@ namespace detail { { // Yes, we do a substring of the non-lowercase value string as we want the exact boundary string std::string_view BoundaryName = std::string_view(ContentTypeHeaderValue).substr(BoundaryPos + 9); + size_t BoundaryEnd = std::string::npos; + while (!BoundaryName.empty() && BoundaryName[0] == ' ') + { + BoundaryName = BoundaryName.substr(1); + } if (!BoundaryName.empty()) { - size_t BoundaryEnd = std::string::npos; - while (BoundaryName[0] == ' ') - { - BoundaryName = BoundaryName.substr(1); - } - if (!BoundaryName.empty()) + if (BoundaryName.size() > 2 && BoundaryName.front() == '"' && BoundaryName.back() == '"') { - if (BoundaryName.size() > 2 && BoundaryName.front() == '"' && BoundaryName.back() == '"') + BoundaryEnd = BoundaryName.find('"', 1); + if (BoundaryEnd != std::string::npos) { - BoundaryEnd = BoundaryName.find('"', 1); - if (BoundaryEnd != std::string::npos) - { - BoundaryBeginMatcher.Init(fmt::format("\r\n--{}", BoundaryName.substr(1, BoundaryEnd - 1))); - return true; - } - } - else - { - BoundaryEnd = BoundaryName.find_first_of(" \r\n"); - BoundaryBeginMatcher.Init(fmt::format("\r\n--{}", BoundaryName.substr(0, BoundaryEnd))); + BoundaryBeginMatcher.Init(fmt::format("\r\n--{}", BoundaryName.substr(1, BoundaryEnd - 1))); return true; } } + else + { + BoundaryEnd = BoundaryName.find_first_of(" \r\n"); + BoundaryBeginMatcher.Init(fmt::format("\r\n--{}", BoundaryName.substr(0, BoundaryEnd))); + return true; + } } } } diff --git a/src/zenhttp/httpclient.cpp b/src/zenhttp/httpclient.cpp index f94c58581..281d512cf 100644 --- a/src/zenhttp/httpclient.cpp +++ b/src/zenhttp/httpclient.cpp @@ -107,17 +107,14 @@ HttpClientBase::GetAccessToken() std::vector<std::pair<uint64_t, uint64_t>> HttpClient::Response::GetRanges(std::span<const std::pair<uint64_t, uint64_t>> OffsetAndLengthPairs) const { - std::vector<std::pair<uint64_t, uint64_t>> Result; - Result.reserve(OffsetAndLengthPairs.size()); if (Ranges.empty()) { - for (const std::pair<uint64_t, uint64_t>& Range : OffsetAndLengthPairs) - { - Result.emplace_back(std::make_pair(Range.first, Range.second)); - } - return Result; + return {}; } + std::vector<std::pair<uint64_t, uint64_t>> Result; + Result.reserve(OffsetAndLengthPairs.size()); + auto BoundaryIt = Ranges.begin(); auto OffsetAndLengthPairIt = OffsetAndLengthPairs.begin(); while (OffsetAndLengthPairIt != OffsetAndLengthPairs.end()) diff --git a/src/zenhttp/include/zenhttp/httpclient.h b/src/zenhttp/include/zenhttp/httpclient.h index f00bbec63..53be36b9a 100644 --- a/src/zenhttp/include/zenhttp/httpclient.h +++ b/src/zenhttp/include/zenhttp/httpclient.h @@ -190,10 +190,12 @@ public: HttpContentType ContentType; }; - // Ranges will map out all recevied ranges, both single and multi-range responses + // Ranges will map out all received ranges, both single and multi-range responses // If no range was requested Ranges will be empty std::vector<MultipartBoundary> Ranges; + // Map the absolute OffsetAndLengthPairs into ResponsePayload from the ranges received (Ranges). + // If the response was not a partial response, an empty vector will be returned std::vector<std::pair<uint64_t, uint64_t>> GetRanges(std::span<const std::pair<uint64_t, uint64_t>> OffsetAndLengthPairs) const; // This contains any errors from the HTTP stack. It won't contain information on |