Skip to content

Commit a667cc6

Browse files
committed
Force using HTTP 1.1 for GitHub REST requests
1 parent 8dc5fc4 commit a667cc6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

runtime/src/main/java/io/quarkiverse/githubapp/runtime/github/GitHubService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.quarkiverse.githubapp.runtime.github;
22

33
import java.io.IOException;
4+
import java.net.http.HttpClient;
5+
import java.net.http.HttpClient.Version;
46
import java.security.GeneralSecurityException;
57
import java.time.temporal.ChronoUnit;
68
import java.util.concurrent.ExecutionException;
@@ -12,6 +14,8 @@
1214
import org.kohsuke.github.GHAppInstallationToken;
1315
import org.kohsuke.github.GitHub;
1416
import org.kohsuke.github.GitHubBuilder;
17+
import org.kohsuke.github.connector.GitHubConnector;
18+
import org.kohsuke.github.extras.HttpClientGitHubConnector;
1519

1620
import com.github.benmanes.caffeine.cache.CacheLoader;
1721
import com.github.benmanes.caffeine.cache.Caffeine;
@@ -35,6 +39,7 @@ public class GitHubService implements GitHubClientProvider {
3539
private final LoadingCache<Long, CachedInstallationToken> installationTokenCache;
3640

3741
private final JwtTokenCreator jwtTokenCreator;
42+
private final GitHubConnector gitHubConnector;
3843

3944
@Inject
4045
public GitHubService(CheckedConfigProvider checkedConfigProvider, JwtTokenCreator jwtTokenCreator) {
@@ -67,6 +72,8 @@ public long expireAfterRead(Long installationId, CachedInstallationToken cachedI
6772
}
6873
})
6974
.build(new CreateInstallationToken());
75+
this.gitHubConnector = new HttpClientGitHubConnector(
76+
HttpClient.newBuilder().version(Version.HTTP_1_1).followRedirects(HttpClient.Redirect.NEVER).build());
7077
}
7178

7279
@Override
@@ -119,6 +126,7 @@ private GitHub createInstallationClient(long installationId) throws IOException
119126
CachedInstallationToken installationToken = installationTokenCache.get(installationId);
120127

121128
final GitHubBuilder gitHubBuilder = new GitHubBuilder()
129+
.withConnector(gitHubConnector)
122130
.withAppInstallationToken(installationToken.getToken())
123131
.withEndpoint(checkedConfigProvider.restApiEndpoint());
124132

@@ -186,6 +194,7 @@ private GitHub createApplicationGitHub() {
186194

187195
try {
188196
final GitHubBuilder gitHubBuilder = new GitHubBuilder()
197+
.withConnector(gitHubConnector)
189198
.withJwtToken(jwtToken)
190199
.withEndpoint(checkedConfigProvider.restApiEndpoint());
191200

0 commit comments

Comments
 (0)