http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.46k stars 119 forks source link

TCP_NODELAY #277

Closed robsmith11 closed 3 years ago

robsmith11 commented 3 years ago

I don't see any way to set TCP_NODELAY (when using linux). Is it not possible?

Fishrock123 commented 3 years ago

short answer: yes, at least for the curl/isahc client.

long answer: you're going to need to piece it together


By default Surf uses IsahcClient i.e. libcurl.

You'll need to create one from an isahc::Client: https://github.com/http-rs/http-client/blob/83b7fb0c1c55051362de22f389be49b65ca85754/src/isahc.rs#L24-L27

Which you'll need to build via isahc::HttpClientBuilder and use methods from the isahc::config::Configurable trait: https://docs.rs/isahc/0.9.10/isahc/struct.HttpClientBuilder.html#impl-Configurable

And the specific setting you'd be looking for is https://docs.rs/isahc/1.0.3/isahc/config/trait.Configurable.html#method.tcp_nodelay

robsmith11 commented 3 years ago

Thanks! I got a bit lost with different layers of abstraction..

So it's not possible to call the config methods on the static default client? Also, I saw that "h1" might become the default http client. Is it possible to set TCP_NODELAY there too?

Fishrock123 commented 3 years ago

So it's not possible to call the config methods on the static default client?

It is not possible to configure the default client at this time.

Is it possible to set TCPNODELAY there (h1 client)_ too?

Not at present. async-std does support TCP_NODELAY, so it would have to be added to this part of http-client: https://github.com/http-rs/http-client/blob/a9928a05732bdbcb33551de1ee2d37f60a43b44f/src/h1.rs#L59-L70

However, http-client currently does not have any way of specify options, see this issue for the beginning of that discussion: https://github.com/http-rs/http-client/issues/61

Fishrock123 commented 3 years ago

WIP draft PR up for the API in http-client: https://github.com/http-rs/http-client/pull/84

Fishrock123 commented 3 years ago

Available in https://github.com/http-rs/surf/releases/tag/v2.3.0