Middleware cannot modify query string parameters?
benferse opened this issue · comments
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?
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.
Can't imagine a reason we shouldn't support that. Can you make a PR for it?