Make JSON and HTTP1 support optional (#286)

* Make json support an optional feature

* Fix Json type documentation

* Make hyper's http1 feature optional
This commit is contained in:
Jonas Platte
2021-10-02 15:46:33 +02:00
committed by GitHub
parent cc4ae6b297
commit 250ea0cfef
7 changed files with 28 additions and 8 deletions
+1
View File
@@ -192,6 +192,7 @@ pub use self::{
request_parts::{BodyStream, RawBody},
};
#[doc(no_inline)]
#[cfg(feature = "json")]
pub use crate::Json;
#[cfg(feature = "multipart")]
+4
View File
@@ -25,9 +25,11 @@ define_rejection! {
pub struct HeadersAlreadyExtracted;
}
#[cfg(feature = "json")]
define_rejection! {
#[status = BAD_REQUEST]
#[body = "Failed to parse the request body as JSON"]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
/// Rejection type for [`Json`](super::Json).
pub struct InvalidJsonBody(Error);
}
@@ -199,11 +201,13 @@ composite_rejection! {
}
}
#[cfg(feature = "json")]
composite_rejection! {
/// Rejection used for [`Json`](super::Json).
///
/// Contains one variant for each way the [`Json`](super::Json) extractor
/// can fail.
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub enum JsonRejection {
InvalidJsonBody,
MissingJsonContentType,