Skip to content

Commit 10db4ab

Browse files
author
Cam Soper
authored
[Breaking change]: [browser] streaming HTTP response is on by deafult (#45667)
Fixes #45644
1 parent b410790 commit 10db4ab

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

docs/core/compatibility/10.0.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Breaking changes in .NET 10
33
titleSuffix: ""
44
description: Navigate to the breaking changes in .NET 10.
5-
ms.date: 04/03/2025
5+
ms.date: 04/08/2025
66
ai-usage: ai-assisted
77
no-loc: [Blazor, Razor, Kestrel]
88
---
@@ -47,6 +47,12 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
4747
| [X509Certificate and PublicKey key parameters can be null](cryptography/10.0/x509-publickey-null.md) | Behavioral/source incompatible change | Preview 3 |
4848
| [Environment variable renamed to DOTNET_OPENSSL_VERSION_OVERRIDE](cryptography/10.0/version-override.md) | Behavioral change | Preview 1 |
4949

50+
## Networking
51+
52+
| Title | Type of change | Introduced version |
53+
|------------------------------------------------------------------------------------------------------------------|-------------------|--------------------|
54+
| [Streaming HTTP responses enabled by default in browser HTTP clients](networking/10.0/default-http-streaming.md) | Behavioral change | Preview 3 |
55+
5056
## SDK and MSBuild
5157

5258
| Title | Type of change | Introduced version |
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: "Breaking change - Streaming HTTP responses enabled by default in browser HTTP clients"
3+
description: "Learn about the breaking change in .NET 10 Preview 3 where streaming HTTP responses are enabled by default in browser HTTP clients."
4+
ms.date: 4/7/2025
5+
ai-usage: ai-assisted
6+
ms.custom: https://github.com/dotnet/docs/issues/45644
7+
---
8+
9+
# Streaming HTTP responses enabled by default in browser HTTP clients
10+
11+
Browser HTTP clients now enable streaming HTTP responses by default. Consequently, the <xref:System.Net.Http.HttpContent.ReadAsStreamAsync*?displayProperty=nameWithType> method now returns a `BrowserHttpReadStream` instead of a <xref:System.IO.MemoryStream>, which does not support synchronous operations. This may require updates to existing code that relies on synchronous stream operations.
12+
13+
## Version introduced
14+
15+
.NET 10 Preview 3
16+
17+
## Previous behavior
18+
19+
In browser environments such as WebAssembly (WASM) and Blazor, the HTTP client buffered the entire response by default. The <xref:System.Net.Http.HttpContent> object contained a <xref:System.IO.MemoryStream> unless you explicitly opted in to streaming responses using the `WebAssemblyEnableStreamingResponse` option.
20+
21+
```csharp
22+
var response = await httpClient.GetAsync("https://example.com");
23+
var contentStream = await response.Content.ReadAsStreamAsync(); // Returns MemoryStream
24+
```
25+
26+
## New behavior
27+
28+
Streaming HTTP responses are now enabled by default. The <xref:System.Net.Http.HttpContent> no longer contains a <xref:System.IO.MemoryStream>. Instead, <xref:System.Net.Http.HttpContent.ReadAsStreamAsync*?displayProperty=nameWithType> returns a `BrowserHttpReadStream`, which does not support synchronous operations.
29+
30+
```csharp
31+
var response = await httpClient.GetAsync("https://example.com");
32+
var contentStream = await response.Content.ReadAsStreamAsync(); // Returns BrowserHttpReadStream
33+
```
34+
35+
## Type of breaking change
36+
37+
This is a [behavioral change](../../categories.md#behavioral-change).
38+
39+
## Reason for change
40+
41+
This change supports use-cases around streaming <xref:System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsAsyncEnumerable*>.
42+
43+
## Recommended action
44+
45+
If your application relies on synchronous stream operations, update the code to use asynchronous alternatives. To disable streaming globally or for specific requests, use the provided configuration options.
46+
47+
To disable streaming for individual requests, use the following:
48+
49+
```csharp
50+
request.Options.Set(new HttpRequestOptionsKey<bool>("WebAssemblyEnableStreamingResponse"), false);
51+
// or
52+
request.SetBrowserResponseStreamingEnabled(false);
53+
```
54+
55+
To disable streaming globally, set the environment variable `DOTNET_WASM_ENABLE_STREAMING_RESPONSE` or add the following to your project file:
56+
57+
```xml
58+
<WasmEnableStreamingResponse>false</WasmEnableStreamingResponse>
59+
```
60+
61+
> [!NOTE]
62+
> As of .NET 10 Preview 3 the `<WasmEnableStreamingResponse>` property is not yet available. It will be available in a future release. For more details, see the [GitHub issue](https://github.com/dotnet/runtime/issues/97449).
63+
64+
## Affected APIs
65+
66+
- <xref:System.Net.Http.HttpContent?displayProperty=fullName>
67+
- <xref:System.Net.Http.HttpContent.ReadAsStreamAsync*?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ items:
4040
items:
4141
- name: Environment variable renamed to DOTNET_ICU_VERSION_OVERRIDE
4242
href: globalization/10.0/version-override.md
43+
- name: Networking
44+
items:
45+
- name: Streaming HTTP responses enabled by default in browser HTTP clients
46+
href: networking/10.0/default-http-streaming.md
4347
- name: SDK and MSBuild
4448
items:
4549
- name: .NET CLI `--interactive` defaults to `true` in user scenarios
@@ -1858,6 +1862,10 @@ items:
18581862
href: maui/7.0/iwindowstatemanager-apis-removed.md
18591863
- name: Networking
18601864
items:
1865+
- name: .NET 10
1866+
items:
1867+
- name: Streaming HTTP responses enabled by default in browser HTTP clients
1868+
href: networking/10.0/default-http-streaming.md
18611869
- name: .NET 9
18621870
items:
18631871
- name: HttpClient metrics report `server.port` unconditionally

0 commit comments

Comments
 (0)