reqwest
reqwest copied to clipboard
Multiple body builder methods in the same request silently overwrite the body
In this example
let client = reqwest::blocking::Client::new();
client.post(url).body("hello").body("world").send().unwrap();
the client will post with a body of just "world".
I think it would be better if the second body()
builder returned an Err
at runtime. (It would be better to track this all with typestate to get compile-time errors, but that would be an impossible API change at this point.)
Issue inspired by this Reddit post. Putting both a form()
and body()
in the same request seems like a reasonably easy mistake to make, and could result in wasted work at best and really confusing behavior at worst.
I think it would be better if the second
body()
builder returned anErr
at runtime.
Returning an Err
is impossible based on the current API:
pub fn body<T: Into<Body>>(mut self, body: T) -> RequestBuilder {}
Ugh. Good point; don't know what I was thinking. panic()
, I guess?