diff --git a/src/http/mod.rs b/src/http/mod.rs index 5ca6ffe7..5759afcd 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -16,16 +16,24 @@ use futures::io::AsyncRead; use futures::AsyncReadExt; /// Receive a GraphQL request from a content type and body. +/// +/// If the content type is multipart it will use `receive_multipart`, otherwise it will use +/// `receive_json`. +#[cfg(feature = "multipart")] pub async fn receive_body( content_type: Option>, body: impl AsyncRead + Send + 'static, opts: MultipartOptions, ) -> Result { - #[cfg(feature = "multipart")] if let Some(Ok(boundary)) = content_type.map(multer::parse_boundary) { - return receive_multipart(body, boundary, opts).await; + receive_multipart(body, boundary, opts).await + } else { + receive_json(body).await } +} +/// Receive a GraphQL request from a body as JSON. +pub async fn receive_json(body: impl AsyncRead + Send + 'static) -> Result { let mut data = Vec::new(); futures::pin_mut!(body); body.read_to_end(&mut data) diff --git a/src/http/multipart.rs b/src/http/multipart.rs index d0952b79..c65d2c33 100644 --- a/src/http/multipart.rs +++ b/src/http/multipart.rs @@ -11,9 +11,12 @@ use std::task::{Context, Poll}; /// Options for `receive_multipart`. #[derive(Default, Clone)] +#[non_exhaustive] pub struct MultipartOptions { - max_file_size: Option, - max_num_files: Option, + /// The maximum file size. + pub max_file_size: Option, + /// The maximum number of files. + pub max_num_files: Option, } impl MultipartOptions {