Add support for HTTP proxy in HTTPRequest

Issue #296 resolved
Koen Serneels created an issue

Hi. We are using the https://tools.ietf.org/html/rfc7523#section-2.2 ‘profile’ to retrieve an access token from aan AAS. Using the API we endup with a TokenRequest which can then be ‘converted' to an HTTPRequest (request.toHTTPRequest()). The way HTTPRequest deals with things (and given the flexibility it already offers) suits our needs perfectly, so we could just 'send’ it. However, our communication has to go via an HTTP proxy. Afaic there no standard way of setting an http proxy on the HTTPRequest.

I see that internally HTTPRequest uses HttpURLConnection . HttpURLConnection supports setting an HTTP proxy on the connection directly, rather than using other means such as system properties (which have impact JVM wide) or using the ProxySelector which is more complicated.

Simply put in : com.nimbusds.oauth2.sdk.http.HTTPRequest L795:

HttpURLConnection conn = (HttpURLConnection)finalURL.openConnection();

it could be fairly trivial to add support for passing a Proxy to the openConnection, something like this:

HttpURLConnection conn = (HttpURLConnection) proxy !=null ? finalURL.openConnection():finalURL.openConnection(proxy);

The proxy could be set via setters on the HttpRequest like the other properties. I believe this would simplify things a lot for users like us that need to use and HTTP proxy. Any chance this can be implemented? Thanks!

Comments (7)

  1. Yavor Vasilev

    Hi Koen,

    Would you be interested in submitting a PR or patch along with some simple tests for the proxy support?

  2. Yavor Vasilev

    Builds are not scheduled here, we release immediately when there’s something worthy to ship.

    Check out v8.4 in a few minutes from Maven Central.

    Thanks for contributing!

  3. Log in to comment