psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.19k stars 9.33k forks source link

Time between request sent and first byte received (time to first byte) #6789

Closed disconnect3d closed 3 months ago

disconnect3d commented 3 months ago

Hi,

It would be awesome if requests allowed for getting the time to first byte metric. Currently, there is the response.elapsed.total_seconds() metric but it computes the time for both sending the request and receiving a response: https://github.com/psf/requests/blob/a3ce6f007597f14029e6b6f54676c34196aa050e/src/requests/sessions.py#L699-L707

This does not allow requests to be used for performance measurements where we want to more accurately measure how much time did it take for a server to render a response.

The request sending goes over an adapter .send method here: https://github.com/psf/requests/blob/a3ce6f007597f14029e6b6f54676c34196aa050e/src/requests/adapters.py#L613-L719

And it eventually does performs the request sending through urllib3. It seems this feature would require changing urllib3 logic to allow for getting this timing properly.

github-actions[bot] commented 3 months ago

As described in the template, Requests is not accepting feature requests