Skip to content

Support http.nonProxyHosts for default proxy in NetHttpTransport #1827

@burkedavison

Description

@burkedavison

https.proxyHost and https.proxyPort are used to create a default proxy when none is explicitly provided.

Oracle documentation on this feature which is linked in our documentation also specifies behavior for http.nonProxyHosts which is not currently supported in the implementation.

Until supported, dynamic proxy behavior can be implemented with a custom ConnectionFactory. Example:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions