mirror of
https://github.com/apple/pkl.git
synced 2026-06-12 16:44:33 +02:00
Clean up http-client changes (#295)
* pkl-excutor tests: symlink 0.25.0 distribution into pkl-executable/build * Use `IoUtils.getPklHomeDir` in HttpClientBuilder * Simplify Exceptions.java * Enable testing for older pkl-executor distribution
This commit is contained in:
@@ -26,24 +26,26 @@ import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import org.pkl.core.Release;
|
||||
import org.pkl.core.util.ErrorMessages;
|
||||
import org.pkl.core.util.IoUtils;
|
||||
|
||||
final class HttpClientBuilder implements HttpClient.Builder {
|
||||
private final Path userHome;
|
||||
private String userAgent;
|
||||
private Duration connectTimeout = Duration.ofSeconds(60);
|
||||
private Duration requestTimeout = Duration.ofSeconds(60);
|
||||
private final Path caCertsDir;
|
||||
private final List<Path> certificateFiles = new ArrayList<>();
|
||||
private final List<URI> certificateUris = new ArrayList<>();
|
||||
|
||||
HttpClientBuilder() {
|
||||
this(Path.of(System.getProperty("user.home")));
|
||||
this(IoUtils.getPklHomeDir().resolve("cacerts"));
|
||||
}
|
||||
|
||||
// only exists for testing
|
||||
HttpClientBuilder(Path userHome) {
|
||||
this.userHome = userHome;
|
||||
HttpClientBuilder(Path caCertsDir) {
|
||||
var release = Release.current();
|
||||
userAgent = "Pkl/" + release.version() + " (" + release.os() + "; " + release.flavor() + ")";
|
||||
this.caCertsDir = caCertsDir;
|
||||
this.userAgent =
|
||||
"Pkl/" + release.version() + " (" + release.os() + "; " + release.flavor() + ")";
|
||||
}
|
||||
|
||||
public HttpClient.Builder setUserAgent(String userAgent) {
|
||||
@@ -80,10 +82,9 @@ final class HttpClientBuilder implements HttpClient.Builder {
|
||||
}
|
||||
|
||||
public HttpClient.Builder addDefaultCliCertificates() {
|
||||
var directory = userHome.resolve(".pkl").resolve("cacerts");
|
||||
var fileCount = certificateFiles.size();
|
||||
if (Files.isDirectory(directory)) {
|
||||
try (var files = Files.list(directory)) {
|
||||
if (Files.isDirectory(caCertsDir)) {
|
||||
try (var files = Files.list(caCertsDir)) {
|
||||
files.filter(Files::isRegularFile).forEach(certificateFiles::add);
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientInitException(e);
|
||||
|
||||
@@ -132,11 +132,18 @@ public class ExecutorSpiImpl implements ExecutorSpi {
|
||||
private HttpClient getOrCreateHttpClient(ExecutorSpiOptions options) {
|
||||
List<Path> certificateFiles;
|
||||
List<URI> certificateUris;
|
||||
if (options instanceof ExecutorSpiOptions2) {
|
||||
var options2 = (ExecutorSpiOptions2) options;
|
||||
certificateFiles = options2.getCertificateFiles();
|
||||
certificateUris = options2.getCertificateUris();
|
||||
} else {
|
||||
try {
|
||||
if (options instanceof ExecutorSpiOptions2) {
|
||||
var options2 = (ExecutorSpiOptions2) options;
|
||||
certificateFiles = options2.getCertificateFiles();
|
||||
certificateUris = options2.getCertificateUris();
|
||||
} else {
|
||||
certificateFiles = List.of();
|
||||
certificateUris = List.of();
|
||||
}
|
||||
// host pkl-executor does not have class ExecutorOptions2 defined.
|
||||
// this will happen if the pkl-executor distribution is too old.
|
||||
} catch (NoClassDefFoundError e) {
|
||||
certificateFiles = List.of();
|
||||
certificateUris = List.of();
|
||||
}
|
||||
|
||||
@@ -20,10 +20,8 @@ public final class Exceptions {
|
||||
|
||||
public static Throwable getRootCause(Throwable t) {
|
||||
var result = t;
|
||||
var cause = result.getCause();
|
||||
while (cause != null) {
|
||||
result = cause;
|
||||
cause = cause.getCause();
|
||||
while (result.getCause() != null) {
|
||||
result = result.getCause();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user