7
7
using System . Collections . Generic ;
8
8
using System . IO ;
9
9
using System . Linq ;
10
+
11
+ #if NETFRAMEWORK
12
+ using System . Net ;
13
+ #endif
14
+
10
15
using System . Net . Http ;
16
+
17
+ #if ! NETFRAMEWORK
18
+
11
19
using System . Security . Authentication ;
20
+
21
+ #endif
22
+
12
23
using System . Text . Json ;
13
24
using System . Text . Json . Serialization ;
14
25
using System . Text . RegularExpressions ;
@@ -22,7 +33,12 @@ public static class ApiResolver
22
33
private static readonly ConcurrentDictionary < string , bool > Releases = new ConcurrentDictionary < string , bool > ( ) ;
23
34
24
35
private static HttpClient HttpClient { get ; } =
25
- new HttpClient ( new HttpClientHandler { SslProtocols = SslProtocols . Tls12 } )
36
+ #if NETFRAMEWORK
37
+ new HttpClient
38
+ #else
39
+ // SslProtocols is only available in .NET Framework 4.7.2 and above
40
+ new HttpClient ( new HttpClientHandler { SslProtocols = SslProtocols . Tls12 } )
41
+ #endif
26
42
{
27
43
BaseAddress = new Uri ( ArtifactsApiUrl )
28
44
} ;
@@ -39,9 +55,10 @@ public static string FetchJson(string path)
39
55
40
56
public static bool IsReleasedVersion ( string version )
41
57
{
42
- if ( Releases . TryGetValue ( version , out var released ) ) return released ;
58
+ if ( Releases . TryGetValue ( version , out var released ) )
59
+ return released ;
43
60
var versionPath = "https://github.com/elastic/elasticsearch/releases/tag/v" + version ;
44
- var message = new HttpRequestMessage { Method = HttpMethod . Head , RequestUri = new Uri ( versionPath ) } ;
61
+ var message = new HttpRequestMessage { Method = HttpMethod . Head , RequestUri = new Uri ( versionPath ) } ;
45
62
46
63
using ( var response = HttpClient . SendAsync ( message ) . GetAwaiter ( ) . GetResult ( ) )
47
64
{
@@ -76,6 +93,14 @@ public static string GetBuildHash(string url)
76
93
77
94
return tokens [ 1 ] ;
78
95
}
96
+
97
+ #if NETFRAMEWORK
98
+ static ApiResolver ( ) =>
99
+ ServicePointManager . SecurityProtocol = ServicePointManager . SecurityProtocol
100
+ & ~ SecurityProtocolType . Ssl3
101
+ & ~ SecurityProtocolType . Tls
102
+ & ~ SecurityProtocolType . Tls11 ;
103
+ #endif
79
104
}
80
105
81
106
internal class ArtifactsVersionsResponse
0 commit comments