Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AgentBuilder should be clonable #675

Open
lefuturiste opened this issue Oct 20, 2023 · 3 comments
Open

AgentBuilder should be clonable #675

lefuturiste opened this issue Oct 20, 2023 · 3 comments

Comments

@lefuturiste
Copy link

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?

@algesten
Copy link
Owner

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 be Clone. This would be a breaking change and force a major version. We have no appetite for that right now, but we've started a FUTURE.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.

@jsha
Copy link
Collaborator

jsha commented Oct 24, 2023

One possible way: rather than implementing Clone (which is infallible), we could have a try_clone() which only succeeds if there is no Middleware.

@algesten
Copy link
Owner

That's a nice idea.

Or clone_without_middleware if we want to be very specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants