AgentConfig should be clonable
lefuturiste opened this issue · comments
Hello,
For my use case, I need to be able to easily "fork" existing agent and create variant, currently I think this is not possible with this library AFAIK.
One of the way could be by allowing user to clone ureq:;AgentBuilder
using the Clone
trait.
Then we can change and have variant without reconstructing the whole AgentBuilder from the start.
Is there is another way to tackle this issue?
Hi @lefuturiste and welcome to ureq!
While I don't object in principle to have AgentBuilder
implement the Clone
trait, there is a hurdle which makes it hard in the short term, and that is Middleware
.
The Agent/builder contains: this:
middleware: Vec<Box<dyn Middleware>>,
There is currently no requirement of Middleware
to implement Clone
, which means this Vec
of middlewares are not clonable either. This leads to one of two solutions:
- Require
Middleware
to beClone
. This would be a breaking change and force a major version. We have no appetite for that right now, but we've started aFUTURE.md
doc in the root where we can add this as a potential consideration for a future major version. - Arc/Mutex lock the middleware chain. This would not be great for performance because Agent manages a pool of connections with the intention of being able to handle many parallel requests. Arc/mutex in that mix would work against those intentions.
One possible way: rather than implementing Clone
(which is infallible), we could have a try_clone()
which only succeeds if there is no Middleware
.
That's a nice idea.
Or clone_without_middleware
if we want to be very specific.
Renaming for ureq 3.x
In ureq 3.x AgentConfig
is indeed clonable including the middleware.