Currently there's a single
timeout option that sets a deadline for the entire request to complete.
This is suboptimal for large files and slow connections, because it doesn't distinguish between the server not responding at all, and the file downloading reliably, but slowly.
In reality there are multiple stages of the request that can time out:
- DNS timeout
- TCP/IP connection timeout
- Waiting for HTTP response headers
- Waiting for each chunk of HTTP response body
I'm thinking of hooking into more of these steps to allow having shorter timeouts as appropriate, e.g. DNS and TCP/IP connection never take more than a few seconds, even if the whole request needs minutes to download.
What should be the API for this? Should we try to interpret existing
.timeout(2000) API in some clever way?