algesten / ureq

A simple, safe HTTP client
Apache License 2.0
1.72k stars 177 forks source link

Feature request: Allow running a request with changed configuration #821

Closed ConradIrwin closed 1 month ago

ConradIrwin commented 1 month ago

I'm looking into Ureq as a replacement for isahc, and one thing we're missing is a nice way to set per-request read timeouts.

I see that in 3.x timeouts can be overridden per request, but only if we go through the Ureq builder. We can do this, but it'd be nice to preserve the current API where we get passed an http::Request<X> and we pass it on down. I tried to create some helper functions where we matched on the method, and called the appropriate builder function; but it looks like the WithBody/WithoutBody types are not exposed, so I can't easily do that.

As you make progress on the v3, it'd be nice to have something like:

agent.request(method: Method) -> RequestBuilder<WithBody>
algesten commented 1 month ago

Hi @ConradIrwin and welcome to ureq!

Interesting problem and it is an oversight, the per-request config is quite new. Maybe we can do something like:

impl Agent {
    pub fn configure_request(&self, request: Request<impl AsSendBody>) -> &mut AgentConfig { ... }
}
algesten commented 1 month ago

The name AgentConfig is increasingly weird with more of these request-level configurations.

ConradIrwin commented 1 month ago

That'd be great!

I am currently building on Ureq 2.x, and just maintaining a pool of agents depending on the timeout (because in reality the connection pool is only helpful when connecting to the same host, and my timeouts are per host).

How "ready" is the 3 branch? If you're at the point you want some production testing, I'd be happy to upgrade now; but if you think we need to wait a bit, I can do that :D.

algesten commented 1 month ago

How "ready" is the 3 branch? If you're at the point you want some production testing, I'd be happy to upgrade now; but if you think we need to wait a bit, I can do that :D.

My plan is to release the 3.0.0-rc1 ASAP. It's mostly held back by that I think I need to write some migration doc. I'm using the main branch in production at work, but it would be great to get feedback on how it works for others too.