java-asana icon indicating copy to clipboard operation
java-asana copied to clipboard

Provide a possibility to customize HttpRequests sent by the API

Open prismec opened this issue 8 years ago • 1 comments

A usecase would be to configure the read and connect timeouts. Currently, the only possibility to do this is e.g.

new Client(new AccessTokenDispatcher(personalAccessToken) {
 @Override
 public HttpRequest buildRequest(String method, GenericUrl url, HttpContent content) throws IOException {
 HttpRequest request = httpTransport.createRequestFactory(req -> {
 req.setConnectTimeout(connectTimeout);
 req.setReadTimeout(readTimeout);
 }).buildRequest(method, url, content);
 request.getHeaders().setAuthorization("Bearer " + personalAccessToken);
 return request;
 }
});

This is problematic because I had to copy over code from the underlying AccessTokenDispatcher and Dispatcher classes.

There are already methods on the Client object taking a HttpTransport object, but due to the nature of the used Http libraries there's no way to construct a HttpTransport object with a HttpRequestInitializer since even the createRequestFactory methods are final.

I guess the easiest solution would be to provide a method on the Client object taking a HttpRequestIntializer.

┆Issue is synchronized with this Asana task

prismec avatar Feb 03 '17 07:02 prismec

https://github.com/Asana/java-asana/pull/48

prismec avatar Feb 03 '17 07:02 prismec