Skip to content

Commit

Permalink
fix: stop RequestBuilder::form() from overwriting previously set `C…
Browse files Browse the repository at this point in the history
…ONTENT_TYPE` (#2527)
  • Loading branch information
0x676e67 authored Jan 17, 2025
1 parent 0f360b8 commit 28d25bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/async_impl/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,11 @@ impl RequestBuilder {
if let Ok(ref mut req) = self.request {
match serde_urlencoded::to_string(form) {
Ok(body) => {
req.headers_mut().insert(
CONTENT_TYPE,
HeaderValue::from_static("application/x-www-form-urlencoded"),
);
req.headers_mut()
.entry(CONTENT_TYPE)
.or_insert(HeaderValue::from_static(
"application/x-www-form-urlencoded",
));
*req.body_mut() = Some(body.into());
}
Err(err) => error = Some(crate::error::builder(err)),
Expand Down
9 changes: 5 additions & 4 deletions src/blocking/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,11 @@ impl RequestBuilder {
if let Ok(ref mut req) = self.request {
match serde_urlencoded::to_string(form) {
Ok(body) => {
req.headers_mut().insert(
CONTENT_TYPE,
HeaderValue::from_static("application/x-www-form-urlencoded"),
);
req.headers_mut()
.entry(CONTENT_TYPE)
.or_insert(HeaderValue::from_static(
"application/x-www-form-urlencoded",
));
*req.body_mut() = Some(body.into());
}
Err(err) => error = Some(crate::error::builder(err)),
Expand Down

0 comments on commit 28d25bd

Please sign in to comment.