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

Middleware cannot modify query string parameters? #741

Closed
benferse opened this issue Mar 21, 2024 · 2 comments · Fixed by #745
Closed

Middleware cannot modify query string parameters? #741

benferse opened this issue Mar 21, 2024 · 2 comments · Fixed by #745

Comments

@benferse
Copy link
Contributor

I tried to write a simple middleware that adds a query string parameter to an outgoing request, but it didn't appear to get included in what actually hit the wire:

struct Foo {}

impl Middleware for Foo {
  fn handle(&self, request: Request, next: MiddlewareNext,) -> Result<ureq::Response, ureq::Error> {
    next.handle(request.query("foo", "bar"))
  }
}

Looking at the logic in Request::do_call this seems intentional - the url that gets captured by the closure that ends up calling Unit::connect is parsed before the middleware chain is run. Is this an oversight, or is modifying the URL in middleware not supported for some reason?

@benferse
Copy link
Contributor Author

I made a local modification to the closure to parse the URL just in time, which works as expected. parse_url is fallible, but that closure's signature already allows a failure for the same Error type, so it seems like a reasonable fix.

@algesten
Copy link
Owner

Can't imagine a reason we shouldn't support that. Can you make a PR for it?

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

Successfully merging a pull request may close this issue.

2 participants