jetty.project
jetty.project copied to clipboard
Per request connection timeout
Jetty version(s)
Jetty 12+
Enhancement Description
Currently it is possible to override the idle timeout on a per-request basis but there doesn't seem to be a way to do the equivalent for connection timeouts:
HttpClient httpClient = new HttpClient();
httpClient.setIdleTimeout(DEFAULT_IDLE_TIMEOUT);
httpClient.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT);
httpClient.newRequest("https://example.com")
.idleTimeout(CUSTOM_IDLE_TIMEOUT, TimeUnit.MILLISECONDS)
// .connectTimeout() - How to override the default connection timeout??
.send();
Whilst it is possible to modify the connection timeout on an existing client, it would not be threadsafe if dispatching multiple requests concurrently.
It seems the only way to ensure a unique connection timeout right now is to create a new client (which adds overhead of a separate connection pool and other resources).
Expected behaviour:
- If there is already a connection in the pool, then then no timeout is applicable, it is just taken from the pool.
- If a new connection needs to be established, use either the request level connection timeout, or otherwise the client level request timeout.
- This should be customisable using the WebSocket client as well via the
JettyUpgradeListener#onHandshakeRequest.
I would be happy to try and make a PR for this if it seems acceptable and feasible?