googleapis / googleapis/google-http-java-client

Support http.nonProxyHosts for default proxy in NetHttpTransport

オープン
#1,827 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
priority: p3 type: feature request
主要言語
Java
スター
1.4k
フォーク
473
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。