Description
Description
This breaking change introduces default support for streaming HTTP responses in browser HTTP clients, which previously required opt-in. This enhancement leverages the capabilities of modern evergreen browsers to improve memory consumption and responsiveness, particularly for large data requests and scenarios like streaming AI chat responses. However, developers should be aware that the response.Content.ReadAsStreamAsync()
method will now return a BrowserHttpReadStream
instead of a MemoryStream
, which does not support synchronous operations. This change may impact existing code that relies on synchronous stream operations.
See dotnet/runtime#111680 for details
Version
.NET 10 Preview 3
Previous behavior
In the Browser/Wasm/Blazor, previously the C# HTTP client buffered the whole response and the HttpContent
contained full MemoryStream
by default. Unless you opted in via WebAssemblyEnableStreamingResponse
HttpRequestOption which enabled the streaming response, typical on other operating systems.
New behavior
The WebAssemblyEnableStreamingResponse
is now opt-out instead of opt-in. The HttpContent
is not MemoryStream
by default.
Type of breaking change
- Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
- Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
- Behavioral change: Existing binaries might behave differently at run time.
Reason for change
To aid use-cases around streaming GetFromJsonAsAsyncEnumerable
which work by default on other OSes.
Recommended action
If you need to disable it globally, you can use
set env variable DOTNET_WASM_ENABLE_STREAMING_RESPONSE
We plan to make the <WasmEnableStreamingResponse>false</WasmEnableStreamingResponse>
in your project file for in future previews of Net 10. See dotnet/runtime#97449
To disable it for individual request, you can use existing
request.Options.Set(new HttpRequestOptionsKey<bool>("WebAssemblyEnableStreamingResponse"), false);
or request.SetBrowserResponseStreamingEnabled(false)
extension in Blazor project
Feature area
Networking
Affected APIs
No response