googleapis / googleapis/google-http-java-client

Support http.nonProxyHosts for default proxy in NetHttpTransport

Aperta
#1,827 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
priority: p3 type: feature request
Lingua principale
Java
Stelle
1.4k
Fork
473
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

`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();
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.