Skip to content

Commit e969f29

Browse files
committed
Fix for Android, which returns true for IsLinux().
1 parent afb4cd5 commit e969f29

9 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private static async ValueTask<SslStream> EstablishSslConnectionAsyncCore(bool a
104104
[SupportedOSPlatform("windows")]
105105
[SupportedOSPlatform("linux")]
106106
[SupportedOSPlatform("macos")]
107+
[UnsupportedOSPlatform("android")]
107108
public static async ValueTask<QuicConnection> ConnectQuicAsync(QuicImplementationProvider quicImplementationProvider, DnsEndPoint endPoint, SslClientAuthenticationOptions? clientAuthenticationOptions, CancellationToken cancellationToken)
108109
{
109110
QuicConnection con = new QuicConnection(quicImplementationProvider, endPoint, clientAuthenticationOptions);

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3Connection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace System.Net.Http
1717
[SupportedOSPlatform("windows")]
1818
[SupportedOSPlatform("linux")]
1919
[SupportedOSPlatform("macos")]
20+
[UnsupportedOSPlatform("android")]
2021
internal sealed class Http3Connection : HttpConnectionBase, IDisposable
2122
{
2223
// TODO: once HTTP/3 is standardized, create APIs for this.

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3ConnectionException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace System.Net.Http
1010
[SupportedOSPlatform("windows")]
1111
[SupportedOSPlatform("linux")]
1212
[SupportedOSPlatform("macos")]
13+
[UnsupportedOSPlatform("android")]
1314
internal sealed class Http3ConnectionException : Http3ProtocolException
1415
{
1516
public Http3ConnectionException(Http3ErrorCode errorCode)

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3ProtocolException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace System.Net.Http
1010
[SupportedOSPlatform("windows")]
1111
[SupportedOSPlatform("linux")]
1212
[SupportedOSPlatform("macos")]
13+
[UnsupportedOSPlatform("android")]
1314
internal class Http3ProtocolException : Exception
1415
{
1516
public Http3ErrorCode ErrorCode { get; }

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace System.Net.Http
1919
[SupportedOSPlatform("windows")]
2020
[SupportedOSPlatform("linux")]
2121
[SupportedOSPlatform("macos")]
22+
[UnsupportedOSPlatform("android")]
2223
internal sealed class Http3RequestStream : IHttpHeadersHandler, IAsyncDisposable, IDisposable
2324
{
2425
private readonly HttpRequestMessage _request;

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionK
121121

122122
_http2Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version20;
123123
// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
124-
if (OperatingSystem.IsLinux() || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
124+
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
125125
{
126126
_http3Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version30 && (_poolManager.Settings._quicImplementationProvider ?? QuicImplementationProviders.Default).IsSupported;
127127
}
@@ -246,7 +246,7 @@ public HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionK
246246
}
247247

248248
// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
249-
if (OperatingSystem.IsLinux() || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
249+
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
250250
{
251251
if (_http3Enabled)
252252
{
@@ -272,9 +272,9 @@ public HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionK
272272
private static List<SslApplicationProtocol> CreateHttp3ApplicationProtocols()
273273
{
274274
// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
275-
if (OperatingSystem.IsLinux() || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
275+
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
276276
{
277-
// TODO: Once the HTTP/3 versions are part of SslApplicationProtocol, move this back to field initialization.
277+
// TODO: Once the HTTP/3 versions are part of SslApplicationProtocol, see https://github.com/dotnet/runtime/issues/1293, move this back to field initialization.
278278
return new List<SslApplicationProtocol>() { Http3Connection.Http3ApplicationProtocol31, Http3Connection.Http3ApplicationProtocol30, Http3Connection.Http3ApplicationProtocol29 };
279279
}
280280

@@ -374,7 +374,7 @@ public byte[] Http2AltSvcOriginUri
374374
}
375375

376376
// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
377-
if (OperatingSystem.IsLinux() || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
377+
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
378378
{
379379
// Either H3 explicitly requested or secured upgraded allowed.
380380
if (_http3Enabled && (request.Version.Major >= 3 || (request.VersionPolicy == HttpVersionPolicy.RequestVersionOrHigher && IsSecure)))
@@ -747,6 +747,7 @@ private void AddHttp2Connection(Http2Connection newConnection)
747747
[SupportedOSPlatform("windows")]
748748
[SupportedOSPlatform("linux")]
749749
[SupportedOSPlatform("macos")]
750+
[UnsupportedOSPlatform("android")]
750751
private async ValueTask<(HttpConnectionBase connection, bool isNewConnection)>
751752
GetHttp3ConnectionAsync(HttpRequestMessage request, HttpAuthority authority, CancellationToken cancellationToken)
752753
{
@@ -920,7 +921,7 @@ public async ValueTask<HttpResponseMessage> SendWithRetryAsync(HttpRequestMessag
920921
}
921922

922923
// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
923-
if (OperatingSystem.IsLinux() || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
924+
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
924925
{
925926
// If an Alt-Svc authority returns 421, it means it can't actually handle the request.
926927
// An authority is supposed to be able to handle ALL requests to the origin, so this is a server bug.

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionSettings.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Net.Quic;
88
using System.Net.Quic.Implementations;
9+
using System.Runtime.Versioning;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112

@@ -86,7 +87,7 @@ public HttpConnectionSettings CloneAndNormalize()
8687
_cookieContainer = new CookieContainer();
8788
}
8889

89-
return new HttpConnectionSettings()
90+
var settings = new HttpConnectionSettings()
9091
{
9192
_allowAutoRedirect = _allowAutoRedirect,
9293
_automaticDecompression = _automaticDecompression,
@@ -118,9 +119,17 @@ public HttpConnectionSettings CloneAndNormalize()
118119
_responseHeaderEncodingSelector = _responseHeaderEncodingSelector,
119120
_enableMultipleHttp2Connections = _enableMultipleHttp2Connections,
120121
_connectCallback = _connectCallback,
121-
_plaintextStreamFilter = _plaintextStreamFilter,
122-
_quicImplementationProvider = _quicImplementationProvider
122+
_plaintextStreamFilter = _plaintextStreamFilter
123123
};
124+
125+
// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
126+
// TODO: Remove if/when QuicImplementationProvider is removed from System.Net.Quic.
127+
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
128+
{
129+
settings._quicImplementationProvider = _quicImplementationProvider;
130+
}
131+
132+
return settings;
124133
}
125134

126135
private static bool AllowHttp2
@@ -178,6 +187,11 @@ private static bool AllowDraftHttp3
178187
public bool EnableMultipleHttp2Connections => _enableMultipleHttp2Connections;
179188

180189
private byte[]? _http3SettingsFrame;
190+
191+
[SupportedOSPlatform("windows")]
192+
[SupportedOSPlatform("linux")]
193+
[SupportedOSPlatform("macos")]
194+
[UnsupportedOSPlatform("android")]
181195
internal byte[] Http3SettingsFrame => _http3SettingsFrame ??= Http3Connection.BuildSettingsFrame(this);
182196
}
183197
}

src/libraries/System.Net.Http/tests/TrimmingTests/HttpClientTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static async Task<int> Main(string[] args)
1919
var quicDllExists = File.Exists(Path.Combine(AppContext.BaseDirectory, quicDll));
2020

2121
// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
22-
if (OperatingSystem.IsLinux() || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
22+
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
2323
{
2424
Console.WriteLine($"Expected {quicDll} is {(quicDllExists ? "present - OK" : "missing - BAD")}.");
2525
return quicDllExists ? 100 : -1;

src/libraries/System.Net.Quic/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<StrongNameKeyId>Microsoft</StrongNameKeyId>
55
<IncludePlatformAttributes>true</IncludePlatformAttributes>
66
<SupportedOSPlatforms>windows;linux;macos</SupportedOSPlatforms>
7+
<UnsupportedOSPlatforms>android</UnsupportedOSPlatforms>
78
</PropertyGroup>
89
</Project>

0 commit comments

Comments
 (0)