Set a default content type for JSON requests
When sending a JSON request a Content-Type of application/json is usually wanted. This is often set as a default for JSON methods by HTTP clients so can be confusing when it is not set. However, we do not want to prevent the user from setting their own Content-Type.
This commit is contained in:
committed by
Martin Algesten
parent
fb158ca73a
commit
28bdb89175
@@ -132,6 +132,9 @@ impl Request {
|
||||
/// ```
|
||||
#[cfg(feature = "json")]
|
||||
pub fn send_json(&mut self, data: SerdeValue) -> Response {
|
||||
if let None = self.header("Content-Type") {
|
||||
self.set("Content-Type", "application/json");
|
||||
}
|
||||
self.do_call(Payload::JSON(data))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user