diff --git a/aspnetcore/blazor/call-web-api.md b/aspnetcore/blazor/call-web-api.md index 55770deffcd4..6b9ae1498e2d 100644 --- a/aspnetcore/blazor/call-web-api.md +++ b/aspnetcore/blazor/call-web-api.md @@ -909,7 +909,32 @@ requestMessage.Headers.Add("X-Requested-With", [ "XMLHttpRequest" ]); Blazor's client-side implementation of uses [Fetch API](https://developer.mozilla.org/docs/Web/API/fetch) and configures the underlying [request-specific Fetch API options](https://developer.mozilla.org/docs/Web/API/fetch#Parameters) via extension methods and . Set additional options using the generic extension method. Blazor and the underlying Fetch API don't directly add or modify request headers. For more information on how user agents, such as browsers, interact with headers, consult external user agent documentation sets and other web resources. -The HTTP response is typically buffered to enable support for synchronous reads on the response content. To enable support for response streaming, use the extension method on the request. +:::moniker range=">= aspnetcore-10.0" + +Response streaming is enabled by default. To opt-out of response streaming, set to `false` on the : + +```csharp +requestMessage.SetBrowserResponseStreamingEnabled(false); +``` + +:::moniker-end + +:::moniker range="< aspnetcore-10.0" + +The HTTP response is typically buffered to enable support for synchronous reads on the response content. To enable support for response streaming, set to `true` on the : + +```csharp +requestMessage.SetBrowserResponseStreamingEnabled(true); +``` + +By default, [`HttpCompletionOption.ResponseContentRead`](xref:System.Net.Http.HttpCompletionOption) is set, which results in the completing after reading the entire response, including the content. In order to be able to use the option on large files, set [`HttpCompletionOption.ResponseHeadersRead`](xref:System.Net.Http.HttpCompletionOption) to avoid caching the file's content in memory: + +```diff +- var response = await Http.SendAsync(requestMessage); ++ var response = await Http.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead); +``` + +:::moniker-end To include credentials in a cross-origin request, use the extension method: diff --git a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md index a5ef914d270d..debcce718b20 100644 --- a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md +++ b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md @@ -36,4 +36,16 @@ The [`[Route]` attribute](xref:Microsoft.AspNetCore.Components.RouteAttribute) n Previously, scrolled to the top of the page for same-page navigations. This behavior has been changed in .NET 10 so that the browser no longer scrolls to the top of the page when navigating to the same page. This means the viewport is no longer reset when making updates to the address for the current page, such as changing the query string or fragment. +### Response streaming is opt-in and how to opt-out + +In prior Blazor releases, response streaming for requests was opt-in. Now, response streaming is enabled by default. + +To opt-out of response streaming, set to `false` on the : + +```csharp +requestMessage.SetBrowserResponseStreamingEnabled(false); +``` + +For more information, see [`HttpClient` and `HttpRequestMessage` with Fetch API request options (*Call web API* article)](xref:blazor/call-web-api?view=aspnetcore-10.0#httpclient-and-httprequestmessage-with-fetch-api-request-options). + -->