diff --git a/change/react-native-windows-cc7e46ad-44db-4623-937f-d2899c415dfa.json b/change/react-native-windows-cc7e46ad-44db-4623-937f-d2899c415dfa.json new file mode 100644 index 00000000000..8fefd35209a --- /dev/null +++ b/change/react-native-windows-cc7e46ad-44db-4623-937f-d2899c415dfa.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Allow >10MB content for blob responses", + "packageName": "react-native-windows", + "email": "julio.rocha@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Shared/Networking/WinRTHttpResource.cpp b/vnext/Shared/Networking/WinRTHttpResource.cpp index 374d89824f2..7c2ec167f67 100644 --- a/vnext/Shared/Networking/WinRTHttpResource.cpp +++ b/vnext/Shared/Networking/WinRTHttpResource.cpp @@ -471,15 +471,23 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect auto inputStream = co_await response.Content().ReadAsInputStreamAsync(); auto reader = DataReader{inputStream}; - // #9510 - 10mb limit on fetch - co_await reader.LoadAsync(10 * 1024 * 1024); + // #9510 - We currently accumulate all incoming request data in 10MB chunks + const uint32_t segmentSize = 10 * 1024 * 1024; // Let response handler take over, if set if (auto responseHandler = self->m_responseHandler.lock()) { if (responseHandler->Supports(reqArgs->ResponseType)) { - auto bytes = vector(reader.UnconsumedBufferLength()); - reader.ReadBytes(bytes); - auto blob = responseHandler->ToResponseData(std::move(bytes)); + // #9510 + vector responseData{}; + while (auto loaded = co_await reader.LoadAsync(segmentSize)) { + auto length = reader.UnconsumedBufferLength(); + auto data = vector(length); + reader.ReadBytes(data); + + responseData.insert(responseData.cend(), data.cbegin(), data.cend()); + } + + auto blob = responseHandler->ToResponseData(std::move(responseData)); if (self->m_onDataDynamic && self->m_onRequestSuccess) { self->m_onDataDynamic(reqArgs->RequestId, std::move(blob)); @@ -495,17 +503,14 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect reader.UnicodeEncoding(UnicodeEncoding::Utf8); } - // #9510 - We currently accumulate all incoming request data in 10MB chunks. - uint32_t segmentSize = 10 * 1024 * 1024; + // #9510 string responseData; winrt::Windows::Storage::Streams::IBuffer buffer; - uint32_t length; - do { - co_await reader.LoadAsync(segmentSize); - length = reader.UnconsumedBufferLength(); + while (auto loaded = co_await reader.LoadAsync(segmentSize)) { + auto length = reader.UnconsumedBufferLength(); if (isText) { - auto data = std::vector(length); + auto data = vector(length); reader.ReadBytes(data); responseData += string(Common::Utilities::CheckedReinterpretCast(data.data()), data.size()); @@ -515,7 +520,7 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect responseData += winrt::to_string(std::wstring_view(data)); } - } while (length > 0); + } if (self->m_onData) { self->m_onData(reqArgs->RequestId, std::move(responseData));