Fix compiling without features
This commit is contained in:
parent
fbcae8aa29
commit
91f059f9ee
@ -16,16 +16,24 @@ use futures::io::AsyncRead;
|
|||||||
use futures::AsyncReadExt;
|
use futures::AsyncReadExt;
|
||||||
|
|
||||||
/// Receive a GraphQL request from a content type and body.
|
/// 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(
|
pub async fn receive_body(
|
||||||
content_type: Option<impl AsRef<str>>,
|
content_type: Option<impl AsRef<str>>,
|
||||||
body: impl AsyncRead + Send + 'static,
|
body: impl AsyncRead + Send + 'static,
|
||||||
opts: MultipartOptions,
|
opts: MultipartOptions,
|
||||||
) -> Result<Request, ParseRequestError> {
|
) -> Result<Request, ParseRequestError> {
|
||||||
#[cfg(feature = "multipart")]
|
|
||||||
if let Some(Ok(boundary)) = content_type.map(multer::parse_boundary) {
|
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<Request, ParseRequestError> {
|
||||||
let mut data = Vec::new();
|
let mut data = Vec::new();
|
||||||
futures::pin_mut!(body);
|
futures::pin_mut!(body);
|
||||||
body.read_to_end(&mut data)
|
body.read_to_end(&mut data)
|
||||||
|
@ -11,9 +11,12 @@ use std::task::{Context, Poll};
|
|||||||
|
|
||||||
/// Options for `receive_multipart`.
|
/// Options for `receive_multipart`.
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct MultipartOptions {
|
pub struct MultipartOptions {
|
||||||
max_file_size: Option<usize>,
|
/// The maximum file size.
|
||||||
max_num_files: Option<usize>,
|
pub max_file_size: Option<usize>,
|
||||||
|
/// The maximum number of files.
|
||||||
|
pub max_num_files: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MultipartOptions {
|
impl MultipartOptions {
|
||||||
|
Loading…
Reference in New Issue
Block a user