Create a ref-assembly package for HttpHandler (#20382)
* Create a ref-assembly package for HttpHandler Fixes #19202
This commit is contained in:
parent
05990683cf
commit
1e70883e87
|
|
@ -9,9 +9,9 @@
|
|||
-->
|
||||
<Dependencies>
|
||||
<ProductDependencies>
|
||||
<Dependency Name="Microsoft.AspNetCore.Components.WebAssembly.Runtime" Version="3.2.0-preview5.20210.1">
|
||||
<Dependency Name="Microsoft.AspNetCore.Components.WebAssembly.Runtime" Version="3.2.0-preview5.20210.3">
|
||||
<Uri>https://github.com/dotnet/blazor</Uri>
|
||||
<Sha>7659b5fda2406d854c72436bdc24f1ff958995f8</Sha>
|
||||
<Sha>f429c0dd1a5dc84a70c66091460747d52475874f</Sha>
|
||||
</Dependency>
|
||||
<Dependency Name="System.Net.Http.Json" Version="3.2.0-preview5.20210.3">
|
||||
<Uri>https://github.com/dotnet/corefx</Uri>
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@
|
|||
<!-- Only listed explicitly to workaround https://github.com/dotnet/cli/issues/10528 -->
|
||||
<MicrosoftNETCorePlatformsPackageVersion>3.1.0</MicrosoftNETCorePlatformsPackageVersion>
|
||||
<!-- Packages from aspnet/Blazor -->
|
||||
<MicrosoftAspNetCoreComponentsWebAssemblyRuntimePackageVersion>3.2.0-preview5.20210.1</MicrosoftAspNetCoreComponentsWebAssemblyRuntimePackageVersion>
|
||||
<MicrosoftAspNetCoreComponentsWebAssemblyRuntimePackageVersion>3.2.0-preview5.20210.3</MicrosoftAspNetCoreComponentsWebAssemblyRuntimePackageVersion>
|
||||
<!-- Packages from aspnet/Extensions -->
|
||||
<InternalAspNetCoreAnalyzersPackageVersion>3.1.3-servicing.20128.2</InternalAspNetCoreAnalyzersPackageVersion>
|
||||
<MicrosoftAspNetCoreAnalyzerTestingPackageVersion>3.1.3-servicing.20128.2</MicrosoftAspNetCoreAnalyzerTestingPackageVersion>
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DevServer", "DevServer", "{
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.WebAssembly.DevServer", "WebAssembly\DevServer\src\Microsoft.AspNetCore.Components.WebAssembly.DevServer.csproj", "{0ED336B7-6FAB-4872-8D75-1CDD5A5DDBB2}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Http", "Http", "{F4995C96-8D4E-4B26-8FB8-614B020156C2}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebAssembly.JSInterop", "WebAssembly.JSInterop", "{37FA056D-A7B3-4F72-A8B9-8D3C175E831E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.JSInterop.WebAssembly", "WebAssembly\JSInterop\src\Microsoft.JSInterop.WebAssembly.csproj", "{FBD7C733-200E-4BED-8B31-2610C2263F72}"
|
||||
|
|
@ -107,6 +109,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Compon
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.WebAssembly.Server.Tests", "WebAssembly\Server\test\Microsoft.AspNetCore.Components.WebAssembly.Server.Tests.csproj", "{72D3D00C-5281-455F-9E19-646EE766009A}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.WebAssembly.HttpHandler", "WebAssembly\WebAssemblyHttpHandler\src\Microsoft.AspNetCore.Comopnents.WebAssembly.HttpHandler.csproj", "{52744BCB-1046-48C0-93A4-19A311A907B2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -537,6 +541,18 @@ Global
|
|||
{72D3D00C-5281-455F-9E19-646EE766009A}.Release|x64.Build.0 = Release|Any CPU
|
||||
{72D3D00C-5281-455F-9E19-646EE766009A}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{72D3D00C-5281-455F-9E19-646EE766009A}.Release|x86.Build.0 = Release|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Release|x64.Build.0 = Release|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -558,6 +574,7 @@ Global
|
|||
{9C41BA92-FBC8-4E11-9A71-0B07906A2D6C} = {B4ACD900-27B6-482B-B434-2C1E86E9D8BC}
|
||||
{A44FB7D1-78AB-41C4-B1C7-94399396EA6C} = {B29FB58D-FAE5-405E-9695-BCF93582BE9A}
|
||||
{0ED336B7-6FAB-4872-8D75-1CDD5A5DDBB2} = {A44FB7D1-78AB-41C4-B1C7-94399396EA6C}
|
||||
{F4995C96-8D4E-4B26-8FB8-614B020156C2} = {B29FB58D-FAE5-405E-9695-BCF93582BE9A}
|
||||
{37FA056D-A7B3-4F72-A8B9-8D3C175E831E} = {B29FB58D-FAE5-405E-9695-BCF93582BE9A}
|
||||
{FBD7C733-200E-4BED-8B31-2610C2263F72} = {37FA056D-A7B3-4F72-A8B9-8D3C175E831E}
|
||||
{7920B09F-8016-49CF-A229-E72D0CECDD17} = {B29FB58D-FAE5-405E-9695-BCF93582BE9A}
|
||||
|
|
@ -591,6 +608,7 @@ Global
|
|||
{710765DD-C2AD-4DBB-A114-14E62F31F463} = {B29FB58D-FAE5-405E-9695-BCF93582BE9A}
|
||||
{DB1DC77D-122E-49E8-AB16-1AC8AEEFEEFF} = {710765DD-C2AD-4DBB-A114-14E62F31F463}
|
||||
{72D3D00C-5281-455F-9E19-646EE766009A} = {7920B09F-8016-49CF-A229-E72D0CECDD17}
|
||||
{52744BCB-1046-48C0-93A4-19A311A907B2} = {F4995C96-8D4E-4B26-8FB8-614B020156C2}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {27A36094-AA50-4FFD-ADE6-C055E391F741}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,6 @@
|
|||
<type fullname="System.ComponentModel.TimeSpanConverter" />
|
||||
</assembly>
|
||||
|
||||
<assembly fullname="WebAssembly.Net.Http">
|
||||
<!-- Without this, the setter for DefaultCredentials would be removed, but we need it -->
|
||||
<type fullname="WebAssembly.Net.Http.HttpClient.FetchCredentialsOption" />
|
||||
<type fullname="WebAssembly.Net.Http.HttpClient.WasmHttpMessageHandler" />
|
||||
</assembly>
|
||||
|
||||
<assembly fullname="System.Text.Json">
|
||||
<!-- S.T.J. uses Activator.CreateInstance to instantiate converters, so we need to preserve default constructors.
|
||||
For safety, do this for all converter types, even though most of them are preserved anyway due to being referenced
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
"System.Memory.dll",
|
||||
"System.Net.Http.dll",
|
||||
"System.Net.Http.Json.dll",
|
||||
"System.Net.Http.WebAssemblyHttpHandler.dll",
|
||||
"System.Numerics.dll",
|
||||
"System.Numerics.Vectors.dll",
|
||||
"System.Runtime.CompilerServices.Unsafe.dll",
|
||||
|
|
@ -94,7 +95,6 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
|||
"System.Xml.dll",
|
||||
"System.Xml.Linq.dll",
|
||||
"WebAssembly.Bindings.dll",
|
||||
"WebAssembly.Net.Http.dll",
|
||||
"WebAssembly.Net.WebSockets.dll",
|
||||
}.OrderBy(i => i, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.WebAssembly.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// The cache mode of the request. It controls how the request will interact with the browser's HTTP cache.
|
||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
|
||||
/// </summary>
|
||||
public enum BrowserRequestCache
|
||||
{
|
||||
/// <summary>
|
||||
/// The browser looks for a matching request in its HTTP cache.
|
||||
/// </summary>
|
||||
Default,
|
||||
|
||||
/// <summary>
|
||||
/// The browser fetches the resource from the remote server without first looking in the cache,
|
||||
/// and will not update the cache with the downloaded resource.
|
||||
/// </summary>
|
||||
NoStore,
|
||||
|
||||
/// <summary>
|
||||
/// The browser fetches the resource from the remote server without first looking in the cache,
|
||||
/// but then will update the cache with the downloaded resource.
|
||||
/// </summary>
|
||||
Reload,
|
||||
|
||||
/// <summary>
|
||||
/// The browser looks for a matching request in its HTTP cache.
|
||||
/// <para>
|
||||
/// If there is a match, fresh or stale, the browser will make a conditional request to the remote server.
|
||||
/// If the server indicates that the resource has not changed, it will be returned from the cache.
|
||||
/// Otherwise the resource will be downloaded from the server and the cache will be updated.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If there is no match, the browser will make a normal request, and will update the cache with the downloaded resource.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
NoCache,
|
||||
|
||||
/// <summary>
|
||||
/// The browser looks for a matching request in its HTTP cache.
|
||||
/// <para>
|
||||
/// If there is a match, fresh or stale, it will be returned from the cache.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If there is no match, the browser will make a normal request, and will update the cache with the downloaded resource.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
ForceCache,
|
||||
|
||||
/// <summary>
|
||||
/// The browser looks for a matching request in its HTTP cache.
|
||||
/// Mode can only be used if the request's mode is "same-origin"
|
||||
/// <para>
|
||||
/// If there is a match, fresh or stale, it will be returned from the cache.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If there is no match, the browser will respond with a 504 Gateway timeout status.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
OnlyIfCached,
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Http
|
|||
/// <summary>
|
||||
/// Specifies a value for the 'credentials' option on outbound HTTP requests.
|
||||
/// </summary>
|
||||
public enum FetchCredentialsOption
|
||||
public enum BrowserRequestCredentials
|
||||
{
|
||||
/// <summary>
|
||||
/// Advises the browser never to send credentials (such as cookies or HTTP auth headers).
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.WebAssembly.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// The mode of the request. This is used to determine if cross-origin requests lead to valid responses
|
||||
/// </summary>
|
||||
public enum BrowserRequestMode
|
||||
{
|
||||
/// <summary>
|
||||
/// If a request is made to another origin with this mode set, the result is simply an error
|
||||
/// </summary>
|
||||
SameOrigin,
|
||||
|
||||
/// <summary>
|
||||
/// Prevents the method from being anything other than HEAD, GET or POST, and the headers from
|
||||
/// being anything other than simple headers.
|
||||
/// </summary>
|
||||
NoCors,
|
||||
|
||||
/// <summary>
|
||||
/// Allows cross-origin requests, for example to access various APIs offered by 3rd party vendors.
|
||||
/// </summary>
|
||||
Cors,
|
||||
|
||||
/// <summary>
|
||||
/// A mode for supporting navigation.
|
||||
/// </summary>
|
||||
Navigate,
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.WebAssembly.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures options for the WebAssembly HTTP message handler.
|
||||
/// </summary>
|
||||
public static class WebAssemblyHttpMessageHandlerOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the default value of the 'credentials' option on outbound HTTP requests.
|
||||
/// Defaults to <see cref="FetchCredentialsOption.SameOrigin"/>.
|
||||
/// </summary>
|
||||
public static FetchCredentialsOption DefaultCredentials
|
||||
{
|
||||
get
|
||||
{
|
||||
var valueString = MonoDefaultCredentialsGetter.Value();
|
||||
var result = default(FetchCredentialsOption);
|
||||
if (valueString != null)
|
||||
{
|
||||
Enum.TryParse(valueString, out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
MonoDefaultCredentialsSetter.Value(value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
static Func<Type> MonoWasmHttpMessageHandlerType = ()
|
||||
=> Assembly.Load("WebAssembly.Net.Http")
|
||||
.GetType("WebAssembly.Net.Http.HttpClient.WasmHttpMessageHandler");
|
||||
|
||||
static Func<Type> MonoFetchCredentialsOptionType = ()
|
||||
=> Assembly.Load("WebAssembly.Net.Http")
|
||||
.GetType("WebAssembly.Net.Http.HttpClient.FetchCredentialsOption");
|
||||
|
||||
static Lazy<PropertyInfo> MonoDefaultCredentialsProperty = new Lazy<PropertyInfo>(
|
||||
() => MonoWasmHttpMessageHandlerType()?.GetProperty("DefaultCredentials", BindingFlags.Public | BindingFlags.Static));
|
||||
|
||||
static Lazy<Func<string>> MonoDefaultCredentialsGetter = new Lazy<Func<string>>(() =>
|
||||
{
|
||||
return () => MonoDefaultCredentialsProperty.Value?.GetValue(null).ToString();
|
||||
});
|
||||
|
||||
static Lazy<Action<string>> MonoDefaultCredentialsSetter = new Lazy<Action<string>>(() =>
|
||||
{
|
||||
var fetchCredentialsOptionsType = MonoFetchCredentialsOptionType();
|
||||
return value => MonoDefaultCredentialsProperty.Value?.SetValue(null, Enum.Parse(fetchCredentialsOptionsType, value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.WebAssembly.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for configuring an instance of <see cref="HttpRequestMessage"/> with browser-specific options.
|
||||
/// </summary>
|
||||
public static class WebAssemblyHttpRequestMessageExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures a value for the 'credentials' option for the HTTP request.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The <see cref="HttpRequestMessage"/>.</param>
|
||||
/// <param name="requestCredentials">The <see cref="BrowserRequestCredentials"/> option.</param>
|
||||
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
|
||||
/// <remarks>
|
||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
|
||||
/// </remarks>
|
||||
public static HttpRequestMessage SetBrowserRequestCredentials(this HttpRequestMessage requestMessage, BrowserRequestCredentials requestCredentials)
|
||||
{
|
||||
if (requestMessage is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(requestMessage));
|
||||
}
|
||||
|
||||
var stringOption = requestCredentials switch
|
||||
{
|
||||
BrowserRequestCredentials.Omit => "omit",
|
||||
BrowserRequestCredentials.SameOrigin => "same-origin",
|
||||
BrowserRequestCredentials.Include => "include",
|
||||
_ => throw new InvalidOperationException($"Unsupported enum value {requestCredentials}.")
|
||||
};
|
||||
|
||||
return SetBrowserRequestOption(requestMessage, "credentials", stringOption);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures a value for the 'cache' option for the HTTP request.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The <see cref="HttpRequestMessage"/>.</param>
|
||||
/// <param name="requestCache">The <see cref="BrowserRequestCache"/> option.</param>
|
||||
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>\
|
||||
/// <remarks>
|
||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
|
||||
/// </remarks>
|
||||
public static HttpRequestMessage SetBrowserRequestCache(this HttpRequestMessage requestMessage, BrowserRequestCache requestCache)
|
||||
{
|
||||
if (requestMessage is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(requestMessage));
|
||||
}
|
||||
|
||||
var stringOption = requestCache switch
|
||||
{
|
||||
BrowserRequestCache.Default => "default",
|
||||
BrowserRequestCache.NoStore => "no-store",
|
||||
BrowserRequestCache.Reload => "reload",
|
||||
BrowserRequestCache.NoCache => "no-cache",
|
||||
BrowserRequestCache.ForceCache => "force-cache",
|
||||
BrowserRequestCache.OnlyIfCached => "only-if-cached",
|
||||
_ => throw new InvalidOperationException($"Unsupported enum value {requestCache}.")
|
||||
};
|
||||
|
||||
return SetBrowserRequestOption(requestMessage, "cache", stringOption);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures a value for the 'mode' option for the HTTP request.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The <see cref="HttpRequestMessage"/>.</param>
|
||||
/// <param name="requestMode">The <see cref="BrowserRequestMode"/>.</param>
|
||||
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>\
|
||||
/// <remarks>
|
||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/Request/mode
|
||||
/// </remarks>
|
||||
public static HttpRequestMessage SetBrowserRequestMode(this HttpRequestMessage requestMessage, BrowserRequestMode requestMode)
|
||||
{
|
||||
if (requestMessage is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(requestMessage));
|
||||
}
|
||||
|
||||
var stringOption = requestMode switch
|
||||
{
|
||||
BrowserRequestMode.SameOrigin => "same-origin",
|
||||
BrowserRequestMode.NoCors => "no-cors",
|
||||
BrowserRequestMode.Cors => "cors",
|
||||
BrowserRequestMode.Navigate => "navigate",
|
||||
_ => throw new InvalidOperationException($"Unsupported enum value {requestMode}.")
|
||||
};
|
||||
|
||||
return SetBrowserRequestOption(requestMessage, "mode", stringOption);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures a value for the 'integrity' option for the HTTP request.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The <see cref="HttpRequestMessage"/>.</param>
|
||||
/// <param name="integrity">The subresource integrity descriptor.</param>
|
||||
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
|
||||
/// <remarks>
|
||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity
|
||||
/// </remarks>
|
||||
public static HttpRequestMessage SetBrowserRequestIntegrity(this HttpRequestMessage requestMessage, string integrity)
|
||||
=> SetBrowserRequestOption(requestMessage, "integrity", integrity);
|
||||
|
||||
/// <summary>
|
||||
/// Configures a value for the HTTP request.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The <see cref="HttpRequestMessage"/>.</param>
|
||||
/// <param name="name">The name of the option, which should correspond to a key defined on https://fetch.spec.whatwg.org/#requestinit</param>
|
||||
/// <param name="value">The value, which must be JSON-serializable.</param>
|
||||
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
|
||||
/// <remarks>
|
||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
|
||||
/// </remarks>
|
||||
public static HttpRequestMessage SetBrowserRequestOption(this HttpRequestMessage requestMessage, string name, object value)
|
||||
{
|
||||
if (requestMessage is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(requestMessage));
|
||||
}
|
||||
|
||||
const string FetchRequestOptionsKey = "WebAssemblyFetchOptions";
|
||||
IDictionary<string, object> fetchOptions;
|
||||
|
||||
if (requestMessage.Properties.TryGetValue(FetchRequestOptionsKey, out var entry))
|
||||
{
|
||||
fetchOptions = (IDictionary<string, object>)entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
fetchOptions = new Dictionary<string, object>(StringComparer.Ordinal);
|
||||
requestMessage.Properties[FetchRequestOptionsKey] = fetchOptions;
|
||||
}
|
||||
|
||||
fetchOptions[name] = value;
|
||||
|
||||
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>
|
||||
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
|
||||
/// <remarks>
|
||||
/// This API is only effective when the browser HTTP Fetch supports streaming.
|
||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream.
|
||||
/// </remarks>
|
||||
public static HttpRequestMessage SetBrowserResponseStreamingEnabled(this HttpRequestMessage requestMessage, bool streamingEnabled)
|
||||
{
|
||||
if (requestMessage is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(requestMessage));
|
||||
}
|
||||
|
||||
requestMessage.Properties["WebAssemblyEnableStreamingResponse"] = streamingEnabled;
|
||||
|
||||
return requestMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,13 +13,17 @@
|
|||
<Reference Include="Microsoft.Extensions.Configuration.Json" />
|
||||
<Reference Include="Microsoft.Extensions.Logging" />
|
||||
<Reference Include="Microsoft.JSInterop.WebAssembly" />
|
||||
<ProjectReference
|
||||
Include="..\..\WebAssemblyHttpHandler\src\Microsoft.AspNetCore.Components.WebAssembly.HttpHandler.csproj"
|
||||
IncludeAssets="commit"
|
||||
ReferenceOutputAssembly="false"
|
||||
Private="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="$(ComponentsSharedSourceRoot)src\BrowserNavigationManagerInterop.cs" />
|
||||
<Compile Include="$(ComponentsSharedSourceRoot)src\JsonSerializerOptionsProvider.cs" />
|
||||
<Compile Include="$(ComponentsSharedSourceRoot)src\WebEventData.cs" />
|
||||
|
||||
<Compile Include="$(ComponentsSharedSourceRoot)src\ElementReferenceJsonConverter.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<PackageId>$(MSBuildProjectName)</PackageId>
|
||||
<AssemblyName>System.Net.Http.WebAssemblyHttpHandler</AssemblyName>
|
||||
<AssemblyVersion>0.2.2.0</AssemblyVersion>
|
||||
<ProduceOnlyReferenceAssembly>true</ProduceOnlyReferenceAssembly>
|
||||
<StrongNameKeyId>Open</StrongNameKeyId>
|
||||
<IsProjectReferenceProvider>false</IsProjectReferenceProvider>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<NuspecProperty Include="OutputPath=$(OutputPath)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace System.Net.Http
|
||||
{
|
||||
public partial class WebAssemblyHttpHandler : System.Net.Http.HttpMessageHandler
|
||||
{
|
||||
public WebAssemblyHttpHandler() { }
|
||||
protected override System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { throw null; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
||||
<metadata>
|
||||
$CommonMetadataElements$
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard2.1" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
$CommonFileElements$
|
||||
<file src="$OutputPath$System.Net.Http.WebAssemblyHttpHandler.dll" target="lib\netstandard2.1\System.Net.Http.WebAssemblyHttpHandler.dll" />
|
||||
</files>
|
||||
</package>
|
||||
|
|
@ -21,8 +21,8 @@
|
|||
'System.dll',
|
||||
'System.Core.dll',
|
||||
'System.Net.Http.dll',
|
||||
'WebAssembly.Bindings.dll',
|
||||
'WebAssembly.Net.Http.dll'
|
||||
'System.Net.Http.WebAssemblyHttpHandler.dll',
|
||||
'WebAssembly.Bindings.dll'
|
||||
]);
|
||||
|
||||
// For these tests we're using Mono's built-in mono_load_runtime_and_bcl util.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@
|
|||
<Reference Include="Microsoft.AspNetCore.Components.Authorization" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.DataAnnotations.Validation" />
|
||||
<Reference Include="Microsoft.Extensions.Logging.Configuration" />
|
||||
<ProjectReference
|
||||
Include="..\..\..\WebAssembly\WebAssemblyHttpHandler\src\Microsoft.AspNetCore.Components.WebAssembly.HttpHandler.csproj"
|
||||
CopyLocal="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -29,4 +32,17 @@
|
|||
<EmbeddedResource Update="Resources.resx" GenerateSource="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="_FixupRefAssembly" AfterTargets="_ResolveBlazorInputs" BeforeTargets="_ResolveBlazorOutputs">
|
||||
<!--
|
||||
ProjectReference doesn't really play well with IncludeAssets behavior you get when referencing
|
||||
the package with IncludeAssets="compile".
|
||||
-->
|
||||
<ItemGroup>
|
||||
<_HttpHandlerAssembly Include="@(_BlazorUserRuntimeAssembly)"
|
||||
Condition="%(_BlazorUserRuntimeAssembly.ProjectReferenceOriginalItemSpec) == '..\..\..\WebAssembly\WebAssemblyHttpHandler\src\Microsoft.AspNetCore.Components.WebAssembly.HttpHandler.csproj'" />
|
||||
|
||||
<_BlazorUserRuntimeAssembly Remove="@(_HttpHandlerAssembly)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
@using Microsoft.AspNetCore.Components.WebAssembly.Http
|
||||
@using System.Net.Http
|
||||
@inject System.Net.Http.HttpClient Http
|
||||
|
||||
<h1>Cookie counter</h1>
|
||||
|
|
@ -32,7 +34,11 @@
|
|||
async Task DoRequest(string url)
|
||||
{
|
||||
requestInProgress = true;
|
||||
responseText = await Http.GetStringAsync(testServerBaseUrl + url);
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, testServerBaseUrl + url);
|
||||
request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
|
||||
using var response = await Http.SendAsync(request);
|
||||
|
||||
responseText = await response.Content.ReadAsStringAsync();
|
||||
requestInProgress = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -28,14 +27,6 @@ namespace BasicTestApp
|
|||
await SimulateErrorsIfNeededForTest();
|
||||
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY")))
|
||||
{
|
||||
// Needed because the test server runs on a different port than the client app,
|
||||
// and we want to test sending/receiving cookies under this config
|
||||
WebAssemblyHttpMessageHandlerOptions.DefaultCredentials = FetchCredentialsOption.Include;
|
||||
}
|
||||
|
||||
builder.RootComponents.Add<Index>("root");
|
||||
|
||||
builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Http
|
||||
@using Microsoft.JSInterop
|
||||
@*#if (!Hosted)
|
||||
@using ComponentsWebAssembly_CSharp
|
||||
|
|
|
|||
Loading…
Reference in New Issue