Skip to content

Commit 2e42586

Browse files
committed
Only use HTTP/2 on certain java versions
Currently we use HTTP/2 as a default but this produces problems with GOAWAY from servers breaking the download on some buggy JDKs. For now we disable HTTP/2 on these unsave versions and only enable it for those where the bug is fixed.
1 parent ac1c442 commit 2e42586

File tree

1 file changed

+22
-1
lines changed
  • providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava

1 file changed

+22
-1
lines changed

providers/bundles/org.eclipse.ecf.provider.filetransfer.httpclientjava/src/org/eclipse/ecf/internal/provider/filetransfer/httpclientjava/ECFHttpClientFactory.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.net.Authenticator;
1717
import java.net.http.HttpClient;
1818
import java.net.http.HttpClient.Redirect;
19+
import java.net.http.HttpClient.Version;
1920
import java.net.http.HttpRequest;
2021
import java.security.NoSuchAlgorithmException;
2122
import java.security.NoSuchProviderException;
@@ -37,6 +38,8 @@
3738
@SuppressWarnings({ "restriction" })
3839
@Component
3940
public class ECFHttpClientFactory implements IHttpClientFactory {
41+
private static final Runtime.Version JDK_BUG_8335181_JAVA21 = Runtime.Version.parse("21.0.8");
42+
private static final Runtime.Version JDK_BUG_8335181_JAVA17 = Runtime.Version.parse("17.0.17");
4043
@SuppressWarnings("unused")
4144
private static final List<String> DEFAULT_PREFERRED_AUTH_SCHEMES_NO_NTLM = Arrays.asList("Basic","Digest");
4245
@SuppressWarnings("unused")
@@ -51,7 +54,7 @@ public class ECFHttpClientFactory implements IHttpClientFactory {
5154

5255
@Override
5356
public HttpClient.Builder newClient() {
54-
HttpClient.Builder builder = HttpClient.newBuilder().followRedirects(Redirect.NORMAL);
57+
HttpClient.Builder builder = HttpClient.newBuilder().version(getDefaultHttpVersion()).followRedirects(Redirect.NORMAL);
5558
String sslContextProvider = HttpClientOptions.HTTPCLIENT_SSLCONTEXT_PROVIDER;
5659
String sslContextProtocol = HttpClientOptions.HTTPCLIENT_SSLCONTEXT_PROTOCOL;
5760
SSLContextFactory sslContextFactory = Activator.getDefault().getSSLContextFactory();
@@ -82,6 +85,24 @@ public HttpClient.Builder run(IHttpClientModifier modifier, HttpClient.Builder v
8285
return builder;
8386
}
8487

88+
private Version getDefaultHttpVersion() {
89+
// See https://bugs.openjdk.org/browse/JDK-8335181
90+
// Version with this bug are prone to spurious GOAWAY
91+
// So we check here if it is safe to use HTTP/2
92+
var version = Runtime.version();
93+
int feature = version.feature();
94+
if (feature >= 25) {
95+
return Version.HTTP_2;
96+
}
97+
if (feature == 17 && version.compareTo(JDK_BUG_8335181_JAVA17) >= 0) {
98+
return Version.HTTP_2;
99+
}
100+
if (feature == 21 && version.compareTo(JDK_BUG_8335181_JAVA21) >= 0) {
101+
return Version.HTTP_2;
102+
}
103+
return Version.HTTP_1_1;
104+
}
105+
85106
@Override
86107
public IHttpClientContext newClientContext() {
87108
IHttpClientContext context = new IHttpClientContext() {

0 commit comments

Comments
 (0)