Skip to content

Commit 0ca87ca

Browse files
Eliminate WebAssemblyHttpMessageHandler and related code, since this is now built into Mono WebAssembly
1 parent 2f700cf commit 0ca87ca

File tree

7 files changed

+4
-413
lines changed

7 files changed

+4
-413
lines changed

src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Net.Http;
6-
using System.Reflection;
75
using System.Threading;
86
using System.Threading.Tasks;
9-
using Microsoft.AspNetCore.Blazor.Http;
107
using Microsoft.AspNetCore.Blazor.Rendering;
118
using Microsoft.Extensions.DependencyInjection;
129
using Microsoft.JSInterop;
@@ -30,16 +27,6 @@ public WebAssemblyHost(IServiceProvider services, IJSRuntime runtime)
3027

3128
public Task StartAsync(CancellationToken cancellationToken = default)
3229
{
33-
// We need to do this as early as possible, it eliminates a bunch of problems. Note that what we do
34-
// is a bit fragile. If you see things breaking because JSRuntime.Current isn't set, then it's likely
35-
// that something on the startup path went wrong.
36-
//
37-
// We want to the JSRuntime created here to be the 'ambient' runtime when JS calls back into .NET. When
38-
// this happens in the browser it will be a direct call from Mono. We effectively needs to set the
39-
// JSRuntime in the 'root' execution context which implies that we want to do as part of a direct
40-
// call from Program.Main, and before any 'awaits'.
41-
SetBrowserHttpMessageHandlerAsDefault();
42-
4330
return StartAsyncAwaited();
4431
}
4532

@@ -102,35 +89,5 @@ public void Dispose()
10289
{
10390
(Services as IDisposable)?.Dispose();
10491
}
105-
106-
private static void SetBrowserHttpMessageHandlerAsDefault()
107-
{
108-
// Within the Mono WebAssembly BCL, this is a special private static field
109-
// that can be assigned to override the default handler
110-
const string getHttpMessageHandlerFieldName = "GetHttpMessageHandler";
111-
var getHttpMessageHandlerField = typeof(HttpClient).GetField(
112-
getHttpMessageHandlerFieldName,
113-
BindingFlags.Static | BindingFlags.NonPublic);
114-
115-
// getHttpMessageHandlerField will be null in tests, but nonnull when actually
116-
// running under Mono WebAssembly
117-
if (getHttpMessageHandlerField != null)
118-
{
119-
// Just in case you're not actually using HttpClient, defer the construction
120-
// of the WebAssemblyHttpMessageHandler
121-
var handlerSingleton = new Lazy<HttpMessageHandler>(
122-
() => new WebAssemblyHttpMessageHandler());
123-
Func<HttpMessageHandler> handlerFactory = () => handlerSingleton.Value;
124-
getHttpMessageHandlerField.SetValue(null, handlerFactory);
125-
}
126-
else
127-
{
128-
// We log a warning in case this ever happens at runtime (even though there's
129-
// no obvious way it could be possible), but don't actually throw because that
130-
// would break unit tests
131-
Console.WriteLine("WARNING: Could not set default HttpMessageHandler because " +
132-
$"'{getHttpMessageHandlerFieldName}' was not found on '{typeof(HttpClient).FullName}'.");
133-
}
134-
}
13592
}
13693
}

src/Components/Blazor/Blazor/src/Http/FetchCredentialsOption.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Components/Blazor/Blazor/src/Http/WebAssemblyHttpMessageHandler.cs

Lines changed: 0 additions & 204 deletions
This file was deleted.

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webassembly.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { navigateTo, internalFunctions as navigationManagerInternalFunctions } from './Services/NavigationManager';
2-
import { internalFunctions as httpInternalFunctions } from './Services/Http';
32
import { attachRootComponentToElement } from './Rendering/Renderer';
43

54
// Make the following APIs available in global scope for invocation from JS
@@ -8,7 +7,6 @@ window['Blazor'] = {
87

98
_internal: {
109
attachRootComponentToElement,
11-
http: httpInternalFunctions,
1210
navigationManager: navigationManagerInternalFunctions,
1311
},
1412
};

0 commit comments

Comments
 (0)