Configurable timeouts on UrlConnection
alienintheheights opened this issue · 6 comments
Configurable timeouts on UrlConnection
Make the timeout value for URL connections configurable, not hardcoded.
Problem
The timeouts for connecting to endpoints are hardcoded in AbstractHttpHelper.buildURLConnection(). They are too short for our environments.
Solution
properties or constructor based timeout options
Alternatives/workarounds
using our own impl for JWK, but we'd rather not because we like fusionauth
Additional context
this is especially problematic when working with various dev environments
How to vote
Please give us a thumbs up or thumbs down as a reaction to help us prioritize this feature. Feel free to comment if you have a particular need or comment on how this feature should work.
Hi @alienintheheights - I'm not finding that class anywhere quickly. Can you provide more information about the code you are referencing here? Where does it exist and how are you seeing the hardcoded values?
I found it by looking at public static List<JSONWebKey> retrieveKeysFromJWKS(String endpoint)
which calls io.fusionauth.http.AbstractHttpHelper
protected static HttpURLConnection buildURLConnection(String endpoint) {
try {
HttpURLConnection urlConnection = (HttpURLConnection) new URL(endpoint).openConnection();
urlConnection.setDoOutput(true);
urlConnection.setConnectTimeout(3_000);
urlConnection.setReadTimeout(2_000);
urlConnection.addRequestProperty("User-Agent", "fusionauth-jwt (https://github.com/FusionAuth/fusionauth-jwt)");
return urlConnection;
} catch (IOException e) {
throw new JSONWebKeySetHelper.JSONWebKeySetException("Failed to build connection to [" + endpoint + "].", e);
}
}
My current workaround is to construct my own HttpURLConnection which I pass to this method instead:
public static List<JSONWebKey> retrieveKeysFromJWKS(HttpURLConnection httpURLConnection) {
But I was hoping to avoid getting that low-level in the client code.
Seems reasonable.
Can you already do this?
For example
JSONWebKeySetHelper.retrieveKeysFromJWKS(HttpURLConnection httpURLConnection);
Maybe not ideal, you'd have to build the connection object, but if you do this, you can specify any time out you like.
Maybe we can add another method that takes a consumer so that you can modify it inline.
Added some additional methods under this comment. baa3457
Will this work for you?
Example usage:
retrieveKeysFromJWKS("https://acme.com/jwks", connection -> connection.setConnectTimeout(5_000));
4.2.0 is released.