Skip to content

Commit 98ac698

Browse files
committed
WASM does not support setting options on HttpClient
1 parent e08a898 commit 98ac698

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

Src/SimpleS3.Extensions.HttpClient/Extensions/CoreBuilderExtensions.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net;
2+
using System.Runtime.InteropServices;
23
using System.Security.Authentication;
34
using Genbox.SimpleS3.Core.Abstracts;
45
using Genbox.SimpleS3.Core.Abstracts.Request;
@@ -30,19 +31,22 @@ public static IHttpClientBuilder UseHttpClient(this ICoreBuilder clientBuilder)
3031

3132
builder.Services.Configure<HttpBuilderActions>(clientBuilder.Name, x =>
3233
{
33-
x.HttpHandlerActions.Add((provider, handler) =>
34+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
3435
{
35-
IOptions<HttpClientConfig> opt = provider.GetRequiredService<IOptions<HttpClientConfig>>();
36-
HttpClientConfig options = opt.Value;
36+
x.HttpHandlerActions.Add((provider, handler) =>
37+
{
38+
IOptions<HttpClientConfig> opt = provider.GetRequiredService<IOptions<HttpClientConfig>>();
39+
HttpClientConfig options = opt.Value;
3740

38-
handler.UseCookies = false;
39-
handler.MaxAutomaticRedirections = 3;
40-
handler.SslProtocols = SslProtocols.None; //Let the OS handle the protocol to use
41-
handler.UseProxy = options.UseProxy;
41+
handler.UseCookies = false;
42+
handler.MaxAutomaticRedirections = 3;
43+
handler.SslProtocols = SslProtocols.None; //Let the OS handle the protocol to use
44+
handler.UseProxy = options.UseProxy;
4245

43-
if (options.Proxy != null)
44-
handler.Proxy = new WebProxy(options.Proxy);
45-
});
46+
if (options.Proxy != null)
47+
handler.Proxy = new WebProxy(options.Proxy);
48+
});
49+
}
4650

4751
x.HttpClientActions.Add((_, client) =>
4852
{

Src/SimpleS3.Extensions.HttpClientFactory/Extensions/CoreBuilderExtensions.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net;
2+
using System.Runtime.InteropServices;
23
using System.Security.Authentication;
34
using Genbox.SimpleS3.Core.Abstracts;
45
using Genbox.SimpleS3.Core.Abstracts.Request;
@@ -43,19 +44,22 @@ public static IHttpClientBuilder UseHttpClientFactory(this ICoreBuilder clientBu
4344
client.DefaultRequestHeaders.TransferEncodingChunked = false;
4445
});
4546

46-
x.HttpHandlerActions.Add((provider, handler) =>
47+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
4748
{
48-
IOptions<HttpClientFactoryConfig> opt = provider.GetRequiredService<IOptions<HttpClientFactoryConfig>>();
49-
HttpClientFactoryConfig config = opt.Value;
50-
51-
handler.UseCookies = false;
52-
handler.MaxAutomaticRedirections = 3;
53-
handler.SslProtocols = SslProtocols.None; //Let the OS handle the protocol to use
54-
handler.UseProxy = config.UseProxy;
55-
56-
if (config.Proxy != null)
57-
handler.Proxy = new WebProxy(config.Proxy);
58-
});
49+
x.HttpHandlerActions.Add((provider, handler) =>
50+
{
51+
IOptions<HttpClientFactoryConfig> opt = provider.GetRequiredService<IOptions<HttpClientFactoryConfig>>();
52+
HttpClientFactoryConfig config = opt.Value;
53+
54+
handler.UseCookies = false;
55+
handler.MaxAutomaticRedirections = 3;
56+
handler.SslProtocols = SslProtocols.None; //Let the OS handle the protocol to use
57+
handler.UseProxy = config.UseProxy;
58+
59+
if (config.Proxy != null)
60+
handler.Proxy = new WebProxy(config.Proxy);
61+
});
62+
}
5963
});
6064

6165
builder.Services.Configure<HttpClientFactoryOptions>(builder.Name, (options, services) =>

0 commit comments

Comments
 (0)