googleapis / googleapis/google-http-java-client

Support http.nonProxyHosts for default proxy in NetHttpTransport

Đang mở
#1,827 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
priority: p3 type: feature request
Ngôn ngữ chính
Java
Star
1.4k
Fork
473
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.