googleapis / googleapis/google-http-java-client

Support http.nonProxyHosts for default proxy in NetHttpTransport

Open
#1,827 0 comments 0 reactions 0 assignees View on GitHub
priority: p3 type: feature request
Dominant language
Java
Stars
1.4k
Forks
473
PR merge metrics
No merged PRs in 30d

Description

`https.proxyHost` and `https.proxyPort` are [used to create a default proxy](https://github.com/googleapis/google-http-java-client/blob/84216c5cfe2f1600464d34661a208cf165e11b9b/google-http-client/src/main/java/com/google/api/client/http/javanet/NetHttpTransport.java#L57-L61) when none is explicitly provided.

Oracle documentation on this feature which is [linked in our documentation](https://cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder#com_google_api_client_http_javanet_NetHttpTransport_Builder_setProxy_java_net_Proxy_) also [specifies behavior for `http.nonProxyHosts`](https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html) which is not currently supported in the implementation.

Until supported, dynamic proxy behavior can be implemented with a custom [`ConnectionFactory`](https://github.com/googleapis/google-http-java-client/blob/84216c5cfe2f1600464d34661a208cf165e11b9b/google-http-client/src/main/java/com/google/api/client/http/javanet/ConnectionFactory.java#L18). Example:
```java
ConnectionFactory connectionFactory = new ConnectionFactory() {
@Override
public HttpURLConnection openConnection(URL url) throws IOException, ClassCastException {
return shouldUseProxy(url) ? url.openConnection(proxy) : url.openConnection();
}
private boolean shouldUseProxy(URL url) {
// Implement by parsing http.nonProxyHosts, or with direct logic.
}
}

HttpTransport transport =
new NetHttpTransport.Builder()
.setConnectionFactory(connectionFactory)
// Do not call .setProxy()
.build();
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.