Skip to content

Commit

Permalink
Add SetBrowserRequestStreamingEnabled extension method (#50481)
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau authored Oct 17, 2023
1 parent 38b164b commit 662795d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
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!

0 comments on commit 662795d

Please sign in to comment.