hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.42k stars 1.59k forks source link

Add option to HttpConnector to enable or disable HttpInfo #2833

Open ho-229 opened 2 years ago

ho-229 commented 2 years ago

Is your feature request related to a problem? Please describe. By default hyper will try to get the HttpInfo for each Response even if they are not needed in most cases. The bottom line is that getpeername and getsockname are actually very slow and they can become a performance bottleneck when making a lot of requests

Describe the solution you'd like Just provide an API like client::Builder::set_host

seanmonstar commented 2 years ago

It could be an option on HttpConnector.

mnpw commented 2 years ago

hey @seanmonstar, I would like to take this up. Please assign this to me 😄

RajivTS commented 2 years ago

@seanmonstar If no one is currently working on this and if this is still needed, I would like to take it up. Also, I think the relevant code is no longer part of the hyper crate and has instead moved into hyper-util.

I noticed your comment on the linked PR of adding the configuration without introducing a new type. However, based on the below snippet, the Connection trait is implemented for tokio::TcpStream which has no access to Config where the new flag will be stored. Do you have any pointers on getting access to this flag without an outer wrapper object?

https://github.com/hyperium/hyper-util/blob/85aade41a080fc4b40a9a53c818680feed14f138/src/client/connect/http.rs#L342-L366

ho-229 commented 1 year ago

I think the calls to peer_addr() and local_addr() should be lazy-loaded, then the connection object would cache the results.