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

Add SetBrowserRequestStreamingEnabled extension method #50481

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Http;
public static class WebAssemblyHttpRequestMessageExtensions
{
private static readonly HttpRequestOptionsKey<IDictionary<string, object>> FetchRequestOptionsKey = new HttpRequestOptionsKey<IDictionary<string, object>>("WebAssemblyFetchOptions");
private static readonly HttpRequestOptionsKey<bool> WebAssemblyEnableStreamingRequestKey = new HttpRequestOptionsKey<bool>("WebAssemblyEnableStreamingRequest");
private static readonly HttpRequestOptionsKey<bool> WebAssemblyEnableStreamingResponseKey = new HttpRequestOptionsKey<bool>("WebAssemblyEnableStreamingResponse");

/// <summary>
Expand Down Expand Up @@ -131,15 +132,35 @@ public static HttpRequestMessage SetBrowserRequestOption(this HttpRequestMessage
return requestMessage;
}

/// <summary>
/// Configures streaming request for the HTTP request.
/// </summary>
/// <param name="requestMessage">The <see cref="HttpRequestMessage"/>.</param>
/// <param name="streamingEnabled"><see langword="true"/> if streaming is enabled; otherwise <see langword="false"/>.</param>
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
/// <remarks>
/// This API is only effective when the browser HTTP Fetch supports request streaming.
/// Requires HTTP/2 or higher server support.
/// See <see href="https://developer.mozilla.org/en-US/docs/Web/API/Request"/>.
/// </remarks>
public static HttpRequestMessage SetBrowserRequestStreamingEnabled(this HttpRequestMessage requestMessage, bool streamingEnabled)
{
ArgumentNullException.ThrowIfNull(requestMessage);

requestMessage.Options.Set(WebAssemblyEnableStreamingRequestKey, streamingEnabled);

return requestMessage;
}

/// <summary>
/// Configures streaming response for the HTTP request.
/// </summary>
/// <param name="requestMessage">The <see cref="HttpRequestMessage"/>.</param>
/// <param name="streamingEnabled"><see langword="true"/> if streaming is enabled; otherwise false.</param>
/// <param name="streamingEnabled"><see langword="true"/> if streaming is enabled; otherwise <see langword="false"/>.</param>
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
/// <remarks>
/// This API is only effective when the browser HTTP Fetch supports streaming.
/// See <see href="https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream"/>.
/// This API is only effective when the browser HTTP Fetch supports response streaming.
/// See <see href="https://developer.mozilla.org/en-US/docs/Web/API/Response"/>.
/// </remarks>
public static HttpRequestMessage SetBrowserResponseStreamingEnabled(this HttpRequestMessage requestMessage, bool streamingEnabled)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
static Microsoft.AspNetCore.Components.WebAssembly.Http.WebAssemblyHttpRequestMessageExtensions.SetBrowserRequestStreamingEnabled(this System.Net.Http.HttpRequestMessage! requestMessage, bool streamingEnabled) -> System.Net.Http.HttpRequestMessage!
Loading