googleapis / googleapis/google-http-java-client
Support http.nonProxyHosts for default proxy in NetHttpTransport
- Vorherrschende Sprache
- Java
- Sterne
- 1.4k
- Forks
- 473
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
`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();
```
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.