-
Notifications
You must be signed in to change notification settings - Fork 329
Add support for HTTP rewrites #1062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -178,6 +178,12 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) { | |||
?: settings.http?.proxy?.noProxy | |||
} | |||
|
|||
private val httpRewrites by lazy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private val httpRewrites by lazy { | |
private val httpRewrites: Map<String, String>? by lazy { |
I know we are inconsistent in this regard, but I think it's better to have the types always defined for properties unless they are absolute obvious from the value. Even if they are private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine with me; I'll change the rest of the properties in this class too
this.userAgent = userAgent; | ||
this.requestTimeout = requestTimeout; | ||
this.testPort = testPort; | ||
this.delegate = delegate; | ||
this.rewrites = | ||
rewrites.entrySet().stream() | ||
.sorted(Comparator.comparingInt((entry) -> entry.getKey().length())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorting by length means we'd pick https://foo.bar/
over https://foo.bar/baz
when both match (because findRewrite
picks the first match), which seems counterintuitive to me.
I'd expect the resolution to be specific -> generic, not the other way around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, this was a bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Some minor comments.
) | ||
} | ||
assertThat(ex.message) | ||
.contains("Rewrite rule must have a lowercased hostname, but was 'www.FOO.com'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we lowercase the host instead of throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, true!
.multiple() | ||
.toMap() | ||
|
||
private fun OptionCallTransformContext.validateRewrite(rewrite: URI) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this being used? I see you are calling IoUtils.validateRewriteRule
which already does validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this was leftover code. Removed.
if (settings.http() != null) { | ||
var httpClientBuilder = HttpClient.builder(); | ||
if (settings.http().proxy() != null) { | ||
var noProxy = settings.http().proxy().noProxy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were we ignoring noProxy rules before? Is this a bugfix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looks like it is.
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. | |||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: You didn't change this file.
Follows the design of apple/pkl-evolution#17