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
Allow direct proxy configuration #435
Conversation
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.
I think going direct instead of using a proxy is specified by passing an absent into the optional proxy configuration higher up in the API, on the ClientConfig.
Is leaving ClientConfig#proxy()
empty not going direct?
|
||
/** | ||
* The hostname and port of the HTTP/HTTPS Proxy. Recognized formats include those recognized by {@link | ||
* com.google.common.net.HostAndPort}, for instance {@code foo.com:80}, {@code 192.168.3.100:8080}, etc. | ||
*/ | ||
public abstract String hostAndPort(); | ||
public abstract Optional<String> hostAndPort(); |
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.
this is an API break that would affect consumers
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.
true. I can add a (deprecated) method that returns a non-optional String and throws when the type is direct. That should not break any existing consumers.
@ash211 ommiting the proxy setting will use |
The third party library is forcing me to configure proxy settings globally. I need to tell service created by http-remoting to explicitly ignore those global settings. |
I'd like to make this explicit by having users configure one of three
things: NO_PROXY, SYSTEM_PROXY, PROXY. Default is probably SYSTEM_PROXY. We
need to do this in a way that doesn't break existing config.
…On Wed, May 24, 2017 at 11:29 AM Lee Avital ***@***.***> wrote:
The third party library is forcing me to configure proxy settings
globally. I need to tell service created by http-remoting to explicitly
ignore those global settings.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#435 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGOdwZ_c_FEbnAcZvJzs9rxNmBNeGInUks5r9HbmgaJpZM4Nlahy>
.
|
Ok, could I can change/add to the names of the Type enum so it reads:
and leave the rest of my PR the same? I don't think that breaks any existing config |
Actually, I think my current approach does this exactly what you want. the default is the system proxy, you can configure directly use of a special proxy or a direct proxy |
but the config space is a little weird, for instance i could say proxy=direct and still specify a hostAndIPort. |
There are preconditions that prevent you from doing that |
let me summarize what i understand the possible valid configurations are:
and these configurations are invalid:
there are still undefined cases, e.g., type=http, but no hostAndPort given |
You're right, that's a mistake on my part. Is the ask that I fix that (it should trigger a failure) or that I change the configuration further? |
@uschi2000 the case you mentioned is handled correctly now @ash211 I had to do some interesting naming because of erasure issues, but I managed to get it so the existing source API is unbroken |
/** | ||
* Use a direct connection. This option will bypass any JVM-level configured proxy settings. | ||
*/ | ||
direct, |
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.
other enums in this project are UPPER_CASE, please do the same here.
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.
These leak into the configuration, which usually doesn't contain upper case values. Glad to change, but that's why I had made this particular enum lowercase
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.
SslConfiguration uses UPPER_CASE, i think. What are example of lower-case configs?
/** | ||
* The hostname and port of the HTTP/HTTPS Proxy. Recognized formats include those recognized by {@link | ||
* com.google.common.net.HostAndPort}, for instance {@code foo.com:80}, {@code 192.168.3.100:8080}, etc. | ||
*/ | ||
public abstract String hostAndPort(); | ||
@JsonProperty("hostAndPort") |
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.
these are snake case host-and-port
usually, but might also need to support hostAndPort
for backcompat
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.
See the builder specified below. This supports deserializing in snake-case and serializing in camel
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.
do you mean deserializing the camel-cased hostAndPort? I don't think that was ever supported because of the annotation @JsonDeserialize(builder = ProxyConfiguration.Builder.class)
@@ -36,45 +36,105 @@ | |||
@Style(visibility = Style.ImplementationVisibility.PACKAGE, builder = "new") | |||
public abstract class ProxyConfiguration { |
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.
please update the ServiceConfiguration#proxyConfiguration docs: if absent, uses system proxy configuration.
|
||
/** | ||
* Credentials if the proxy needs authentication. | ||
*/ | ||
public abstract Optional<BasicCredentials> credentials(); | ||
|
||
@Value.Default |
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.
document default.
Preconditions.checkArgument(host.hasPort(), "Given hostname does not contain a port number: " + host); | ||
switch (type()) { | ||
case http: | ||
HostAndPort host = HostAndPort.fromString(maybeHostAndPort().get()); |
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.
doesn't this NPE when type=http and no host is specified?
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.
Nice catch yes
enum is now upper cased |
} | ||
|
||
if (credentials().isPresent()) { | ||
Preconditions.checkArgument(type() == Type.HTTP, "credentials only valid for http proxies"); |
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: "for HTTP proxies"
switch (type()) { | ||
case HTTP: | ||
Preconditions.checkArgument(maybeHostAndPort().isPresent(), "host-and-port must be " | ||
+ "configured for an http proxy"); |
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.
HTTP
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.
one last nit, sorry. otherwise looks good to me.
@ash211 anything left regarding the serialization format? |
@uschi2000 I'm good as long as it's not a backcompat break! Doesn't look like it, but I'm not familiar with Jackson intricacies |
This allows users to bypass the proxy settings set at the JVM with
-Dhttps.proxyHost
/-Dhttps.proxyPort
. This can be useful if you are using a third-party library which needs to make proxied http calls, but the library does not allow you to set an external proxy.Previously okhttp would default to using a direct connection if the proxy failed, but that changed in 3.5.0 (https://github.com/square/okhttp/blob/master/CHANGELOG.md)
This change is