mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
[PR #217] [MERGED] Use java.net.http.HttpClient instead of java.net.Http(s)URLConnection #458
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/217
Author: @odenix
Created: 2/20/2024
Status: ✅ Merged
Merged: 3/6/2024
Merged by: @bioball
Base:
main← Head:http-client📝 Commits (10+)
9ac214aUse java.net.http.HttpClient instead of java.net.Http(s)URLConnectiondc78962Support CA certificates in Executor API903f141Build CLI HTTP client lazily1ca9814Improve handling of HTTP client initialization errors765b439Improve SSL related error messages988481fRename class0022ea3Rename some internals0b3734dRemove assert that is specific to JDK implementation8f8ac86Fix compile error on JDK 11b12db60Incorporate review feedback📊 Changes
79 files changed (+2376 additions, -395 deletions)
View changed files
📝
bench/src/jmh/java/org/pkl/core/ListSort.java(+2 -0)📝
docs/src/test/kotlin/DocSnippetTests.kt(+2 -0)📝
gradle/libs.versions.toml(+1 -0)➕
pkl-certs/pkl-certs.gradle.kts(+19 -0)📝
pkl-certs/src/main/resources/org/pkl/certs/PklCARoots.pem(+0 -0)📝
pkl-cli/pkl-cli.gradle.kts(+1 -1)📝
pkl-cli/src/main/kotlin/org/pkl/cli/CliPackageDownloader.kt(+1 -1)📝
pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectPackager.kt(+1 -0)📝
pkl-cli/src/main/kotlin/org/pkl/cli/CliProjectResolver.kt(+1 -0)📝
pkl-cli/src/main/kotlin/org/pkl/cli/CliRepl.kt(+1 -0)📝
pkl-cli/src/main/kotlin/org/pkl/cli/CliServer.kt(+1 -1)📝
pkl-cli/src/test/kotlin/org/pkl/cli/CliEvaluatorTest.kt(+45 -13)📝
pkl-cli/src/test/kotlin/org/pkl/cli/CliPackageDownloaderTest.kt(+1 -1)📝
pkl-cli/src/test/kotlin/org/pkl/cli/CliProjectPackagerTest.kt(+8 -5)📝
pkl-cli/src/test/kotlin/org/pkl/cli/repl/ReplMessagesTest.kt(+2 -0)📝
pkl-commons-cli/pkl-commons-cli.gradle.kts(+1 -0)📝
pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliBaseOptions.kt(+29 -6)📝
pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt(+6 -7)📝
pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/commands/BaseOptions.kt(+2 -31)📝
pkl-commons-test/pkl-commons-test.gradle.kts(+1 -0)...and 59 more files
📄 Description
Moving to java.net.http.HttpClient brings many benefits, including HTTP/2 support and the ability to make asynchronous requests.
Major additions and changes:
Each HTTP client maintains its own connection pool and SSLContext. For efficiency reasons, I've tried 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).
Fixes #157.
Note: This PR allows to fix the "flaky PackageServer tests" problem in a principled way. Because all HTTP requests are now routed through HttpClient, PackageServer can bind to a dynamic port, and HttpClient can rewrite requests to use that port in test mode. I've tested this approach on a local branch, and it's the first time I can get "gw clean build" to pass without "connection refused" errors.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.