mirror of https://github.com/fafhrd91/actix-web
add awc::ClientResponse::json_with_content_type_unchecked
This commit is contained in:
parent
a3806cde19
commit
420b17d985
|
@ -203,15 +203,25 @@ where
|
||||||
MessageBody::new(self)
|
MessageBody::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads and parse `application/json` encoded body.
|
/// Loads and parses `application/json` encoded body.
|
||||||
/// Return `JsonBody<T>` future. It resolves to a `T` value.
|
/// Returns a s`JsonBody<T>` future. It resolves to a `T` value.
|
||||||
///
|
///
|
||||||
/// Returns error:
|
/// Returns error:
|
||||||
///
|
///
|
||||||
/// * content type is not `application/json`
|
/// * content type is not `application/json`
|
||||||
/// * content length is greater than 256k
|
/// * content length is greater than 256k
|
||||||
pub fn json<T: DeserializeOwned>(&mut self) -> JsonBody<S, T> {
|
pub fn json<T: DeserializeOwned>(&mut self) -> JsonBody<S, T> {
|
||||||
JsonBody::new(self)
|
JsonBody::new(self, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Loads and parses `application/json` encoded body.
|
||||||
|
/// Returns a `JsonBody<T>` future. It resolves to a `T` value.
|
||||||
|
///
|
||||||
|
/// Returns error:
|
||||||
|
///
|
||||||
|
/// * content length is greater than 256k
|
||||||
|
pub fn json_with_content_type_unchecked<T: DeserializeOwned>(&mut self) -> JsonBody<S, T> {
|
||||||
|
JsonBody::new(self, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,14 +347,17 @@ where
|
||||||
U: DeserializeOwned,
|
U: DeserializeOwned,
|
||||||
{
|
{
|
||||||
/// Create `JsonBody` for request.
|
/// Create `JsonBody` for request.
|
||||||
pub fn new(res: &mut ClientResponse<S>) -> Self {
|
pub fn new(res: &mut ClientResponse<S>, check_content_type: bool) -> Self {
|
||||||
// check content-type
|
// Create a function to check content-type
|
||||||
let json = if let Ok(Some(mime)) = res.mime_type() {
|
let json = || {
|
||||||
|
if let Ok(Some(mime)) = res.mime_type() {
|
||||||
mime.subtype() == mime::JSON || mime.suffix() == Some(mime::JSON)
|
mime.subtype() == mime::JSON || mime.suffix() == Some(mime::JSON)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if !json {
|
|
||||||
|
if check_content_type && !json() {
|
||||||
return JsonBody {
|
return JsonBody {
|
||||||
length: None,
|
length: None,
|
||||||
fut: None,
|
fut: None,
|
||||||
|
|
Loading…
Reference in New Issue