I'm trying to perform a request to an http endpoint that streams data for a non-trivial amount of time with Jetty HttpClient. I want to setup a timeout to bound the request time budget. I'm expecting to give up after a precise amount of time in case I'm not receiving any data, but to let the request finish if it started to stream the response.
httpClient.newRequest("http://some-host.local/an/endpoint/that/streams)
.method(HttpMethod.GET)
.idleTimeout(100, TimeUnit.MILLISECONDS)
.timeout(2000, TimeUnit.MILLISECONDS)
.send();
I understand that the request goes trough several states: Queued,Begin, [...], Completed. I found these two timeouts:
timeout()- Starts on the Queued state; it is disabled on Completed state.idleTimeout()- Starts after the Begin state; it is reset each time content arrives; it is disabled on Completed state
When many requests are Queued but not yet Begin (e.g. all connections are used), the idleTimeout() does not apply to them. A request can only be evicted from the queue by a timeout expiration.
The problem I am facing is that I'm having troubles to set a meaningful timeout that allows me to stop a request that takes too long to start, without also stopping requests that are receiving streamed data.
Is there a way to take into account the time spent awaiting in the queue? I'm trying to bound the time from send() to first byte received.