Use java.net.http.HttpClient instead of java.net.Http(s)URLConnection (#217)

Moving to java.net.http.HttpClient brings many benefits, including
HTTP/2 support and the ability to make asynchronous requests.

Major additions and changes:
- Introduce a lightweight org.pkl.core.http.HttpClient API.
  This keeps some flexibility and allows to enforce behavior
  such as setting the User-Agent header.
- Provide an implementation that delegates to java.net.http.HttpClient.
- Use HttpClient for all HTTP(s) requests across the codebase.
  This required adding an HttpClient parameter to constructors and
  factory methods of multiple classes, some of which are public APIs.
- Manage CA certificates per HTTP client instead of per JVM.
  This makes it unnecessary to set JVM-wide system/security properties
  and default SSLSocketFactory's.
- Add executor v2 options to the executor SPI
- Add pkl-certs as a new artifact, and remove certs from pkl-commons-cli artifact

Each HTTP client maintains its own connection pool and SSLContext.
For efficiency reasons, It's best to reuse clients whenever feasible.
To avoid memory leaks, clients are not stored in static fields.

HTTP clients are expensive to create. For this reason,
EvaluatorBuilder defaults to a "lazy" client that creates the underlying
java.net.http.HttpClient on the first send (which may never happen).
This commit is contained in:
translatenix
2024-03-06 10:25:56 -08:00
committed by GitHub
parent 106743354c
commit 3f3dfdeb1e
79 changed files with 2376 additions and 395 deletions

View File

@@ -940,6 +940,31 @@ ioErrorMakingHttpGet=\
Exception when making request `GET {0}`:\n\
{1}
errorConnectingToHost=\
Error connecting to host `{0}`.
errorSslHandshake=\
Error during SSL handshake with host `{0}`:\n\
{1}
cannotInitHttpClient=\
Error initializing HTTP client:\n\
{0}
cannotFindCertFile=\
Cannot find CA certificate file `{0}`.
cannotReadCertFile=\
Error reading CA certificate file `{0}`:\n\
{1}
cannotParseCertFile=\
Error parsing CA certificate file `{0}`:\n\
{1}
emptyCertFile=\
CA certificate file `{0}` is empty.
invalidPackageZipUrl=\
Expected the zip asset for package `{0}` to be an HTTPS URI, but got `{1}`.
@@ -1019,3 +1044,11 @@ The only supported checksum algorithm is sha256.
testsFailed=\
Tests failed.
expectedJarOrFileUrl=\
Certificates can only be loaded from `jar:` or `file:` URLs, but got:\n\
{0}
cannotFindBuiltInCertificates=\
Cannot find Pkl's trusted CA certificates on the class path.\n\
To fix this problem, add dependendy `org.pkl:pkl-certs`.