Skip to content

Commit b26b91f

Browse files
committed
Incorporate review feedback (more to follow later)
- use uri instead of response.uri()/redirected when constructing ResolvedModuleKey - add docs for HttpClient implementations
1 parent a46e0fc commit b26b91f

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

pkl-core/src/main/java/org/pkl/core/http/DummyHttpClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.net.http.HttpResponse.BodyHandler;
2121
import javax.annotation.concurrent.ThreadSafe;
2222

23+
/** An {@code HttpClient} implementation that throws {@code AssertionError} on every send. */
2324
@ThreadSafe
2425
final class DummyHttpClient implements HttpClient {
2526
@Override

pkl-core/src/main/java/org/pkl/core/http/JdkHttpClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.pkl.core.util.ErrorMessages;
5252
import org.pkl.core.util.Exceptions;
5353

54+
/** An {@code HttpClient} implementation backed by {@link java.net.http.HttpClient}. */
5455
@ThreadSafe
5556
final class JdkHttpClient implements HttpClient {
5657
// non-private for testing

pkl-core/src/main/java/org/pkl/core/http/LazyHttpClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
import javax.annotation.concurrent.GuardedBy;
2525
import javax.annotation.concurrent.ThreadSafe;
2626

27+
/**
28+
* An {@code HttpClient} implementation that defers creating the underlying HTTP client until the
29+
* first send. A potential drawback of using {@code LazyHttpClient} is that any {@link
30+
* HttpClientInitException} thrown by the underlying client is equally deferred.
31+
*/
2732
@ThreadSafe
2833
class LazyHttpClient implements HttpClient {
2934
private final Supplier<HttpClient> supplier;

pkl-core/src/main/java/org/pkl/core/http/RequestRewritingClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
import java.util.concurrent.atomic.AtomicBoolean;
2424
import javax.annotation.concurrent.ThreadSafe;
2525

26+
/**
27+
* An {@code HttpClient} decorator that
28+
*
29+
* <ul>
30+
* <li>overrides the {@code User-Agent} header of {@code HttpRequest}s
31+
* <li>sets a request timeout if none is present
32+
* <li>ensures that {@link #close()} is idempotent.
33+
* </ul>
34+
*
35+
* <p>Both {@code User-Agent} header and default request timeout are configurable through {@link
36+
* HttpClient.Builder}.
37+
*/
2638
@ThreadSafe
2739
final class RequestRewritingClient implements HttpClient {
2840
// non-private for testing

pkl-core/src/main/java/org/pkl/core/module/ModuleKeys.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ public ResolvedModuleKey resolve(SecurityManager securityManager)
492492
HttpUtils.checkHasStatusCode200(response);
493493
securityManager.checkResolveModule(response.uri());
494494
String text = IoUtils.readString(body);
495-
return ResolvedModuleKeys.virtual(this, response.uri(), text, true);
495+
// intentionally use uri instead of response.uri()
496+
return ResolvedModuleKeys.virtual(this, uri, text, true);
496497
}
497498
}
498499

@@ -509,7 +510,8 @@ public ResolvedModuleKey resolve(SecurityManager securityManager)
509510
}
510511
securityManager.checkResolveModule(redirected);
511512
var text = IoUtils.readString(stream);
512-
return ResolvedModuleKeys.virtual(this, redirected, text, true);
513+
// intentionally use uri instead of redirected
514+
return ResolvedModuleKeys.virtual(this, uri, text, true);
513515
}
514516
}
515517
}

0 commit comments

Comments
 (0)