|
16 | 16 | import java.net.Authenticator; |
17 | 17 | import java.net.http.HttpClient; |
18 | 18 | import java.net.http.HttpClient.Redirect; |
| 19 | +import java.net.http.HttpClient.Version; |
19 | 20 | import java.net.http.HttpRequest; |
20 | 21 | import java.security.NoSuchAlgorithmException; |
21 | 22 | import java.security.NoSuchProviderException; |
@@ -51,7 +52,7 @@ public class ECFHttpClientFactory implements IHttpClientFactory { |
51 | 52 |
|
52 | 53 | @Override |
53 | 54 | public HttpClient.Builder newClient() { |
54 | | - HttpClient.Builder builder = HttpClient.newBuilder().followRedirects(Redirect.NORMAL); |
| 55 | + HttpClient.Builder builder = HttpClient.newBuilder().version(getDefaultHttpVersion()).followRedirects(Redirect.NORMAL); |
55 | 56 | String sslContextProvider = HttpClientOptions.HTTPCLIENT_SSLCONTEXT_PROVIDER; |
56 | 57 | String sslContextProtocol = HttpClientOptions.HTTPCLIENT_SSLCONTEXT_PROTOCOL; |
57 | 58 | SSLContextFactory sslContextFactory = Activator.getDefault().getSSLContextFactory(); |
@@ -82,6 +83,24 @@ public HttpClient.Builder run(IHttpClientModifier modifier, HttpClient.Builder v |
82 | 83 | return builder; |
83 | 84 | } |
84 | 85 |
|
| 86 | + private Version getDefaultHttpVersion() { |
| 87 | + // See https://bugs.openjdk.org/browse/JDK-8335181 |
| 88 | + // Version with this bug are prone to spurious GOAWAY |
| 89 | + // So we check here if it is safe to use HTTP/2 |
| 90 | + var version = Runtime.version(); |
| 91 | + int feature = version.feature(); |
| 92 | + if (feature >= 25) { |
| 93 | + return Version.HTTP_2; |
| 94 | + } |
| 95 | + if (feature == 17 && version.compareTo(java.lang.Runtime.Version.parse("17.0.17")) >= 0) { |
| 96 | + return Version.HTTP_2; |
| 97 | + } |
| 98 | + if (feature == 21 && version.compareTo(java.lang.Runtime.Version.parse("21.0.8")) >= 0) { |
| 99 | + return Version.HTTP_2; |
| 100 | + } |
| 101 | + return Version.HTTP_1_1; |
| 102 | + } |
| 103 | + |
85 | 104 | @Override |
86 | 105 | public IHttpClientContext newClientContext() { |
87 | 106 | IHttpClientContext context = new IHttpClientContext() { |
|
0 commit comments