Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response streaming opt-out #34870

Open
guardrex opened this issue Mar 3, 2025 · 0 comments · May be fixed by #34894
Open

Response streaming opt-out #34870

guardrex opened this issue Mar 3, 2025 · 0 comments · May be fixed by #34894

Comments

@guardrex
Copy link
Collaborator

guardrex commented Mar 3, 2025

UPDATE (3/5): The PR is up at 👉 #34894. Let's take up the discussion there.

Description

@pavelsavara @campersau ... In addition to covering the opt-out feature for 10.0, it looks like the current guidance is incomplete. Please correct me if I'm wrong in the following remarks.

Existing remarks and opt-in behavior <10.0

Our only existing remark on this subject is ...

The HTTP response is typically buffered to enable support for synchronous reads on the response content. To enable support for response streaming, use the <xref:Microsoft.AspNetCore.Components.WebAssembly.Http
.WebAssemblyHttpRequestMessageExtensions.SetBrowserResponseStreamingEnabled%2A> extension method on the request.

Cross-ref: https://learn.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-9.0#httpclient-and-httprequestmessage-with-fetch-api-request-options

It looks now like that's incomplete because of ...

In order to be able to use WebAssemblyEnableStreamingResponse/SetBrowserResponseStreamingEnabled option on large files, the user should also set HttpCompletionOption.ResponseHeadersRead so that the content would not be cached in memory. The default is ResponseContentRead which makes HttpClient to "... complete after reading the entire response including the content."

Cross-ref: dotnet/runtime#60287 (comment)

I wasn't aware of additional remarks on that, such as ...

I guess it would be great to also mention the HttpCompletionOption.ResponseHeadersRead in the docs as well.

Cross-ref: dotnet/runtime#60339 (comment)

I plan to add it to the existing coverage in a paragraph with the following example, which dovetails with our current example code ...

- var response = await Http.SendAsync(requestMessage);
+ var response = await Http.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead);

New API >=10.0

First, what Preview release is this landing for?

As of dotnet/runtime#111680 for 10.0, response streaming will be enabled by default with the following API to opt-out ...

request.Options.Set(new HttpRequestOptionsKey<bool>("WebAssemblyEnableStreamingResponse"), false);

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-9.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/call-web-api.md

Document ID

c7e59a08-1c60-32c2-75fd-33cb77ff7a5d

Article author

@guardrex

Metadata

  • ID: 8b5e2e10-ff7b-2b9f-84da-f16028ae2c53
  • PlatformId: 32bfc271-12a7-7ce3-dcec-43ac2e8c68d7
  • Service: aspnet-core
  • Sub-service: blazor

Related Issues

@guardrex guardrex added ⌚ Not Triaged Source - Docs.ms Docs Customer feedback via GitHub Issue labels Mar 3, 2025
@github-project-automation github-project-automation bot moved this to Triage in Blazor.Docs Mar 3, 2025
@github-actions github-actions bot added the Blazor label Mar 3, 2025
@guardrex guardrex added 10.0 .NET 10 and removed Source - Docs.ms Docs Customer feedback via GitHub Issue ⌚ Not Triaged labels Mar 3, 2025
@dotnet dotnet deleted a comment from github-actions bot Mar 3, 2025
@guardrex guardrex moved this from Triage to 10.0 in Blazor.Docs Mar 3, 2025
@guardrex guardrex moved this from 10.0 to In progress in Blazor.Docs Mar 5, 2025
@guardrex guardrex linked a pull request Mar 5, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

Successfully merging a pull request may close this issue.

1 participant