Require JSON content-type

This commit is contained in:
Koxiaet 2020-10-15 18:30:16 +01:00
parent 7caff6beee
commit 2756c2cd5b
4 changed files with 19 additions and 2 deletions

View File

@ -5,8 +5,7 @@ This directory provides various integrations for `async-graphql` to various crat
## Requirements for an HTTP integration
This is a list of criteria for HTTP integrations with `async-graphql` in order to make sure all
integrations are implemented consistently. Currently not all integrations follow this criteria, but
we are working on it.
integrations are implemented consistently.
Integrations may provide additional functionality to better integrate with the specific library, but
they must all internally use the below functions.
@ -37,3 +36,10 @@ they must all internally use the below functions.
1. Stream all websocket messages that send data (bytes/text/continuations) to the
`async_graphql::http::WebSocket`.
1. Convert all responses to websocket text responses.
## Integration Status
- Actix-web: Complete integration.
- Rocket: Missing websocket support.
- Tide: Missing websocket support (blocked on [support in Tide itself](https://github.com/http-rs/tide/issues/67)).
- Warp: Complete integration.

View File

@ -3,6 +3,9 @@
//! Note: This integrates with the unreleased version 0.5 of Rocket, and so breaking changes in
//! both this library and Rocket are to be expected.
//!
//! To configure options for sending and receiving multipart requests, add your instance of
//! `MultipartOptions` to the state managed by Rocket (`.manage(your_multipart_options)`).
//!
//! **[Full Example](<https://github.com/async-graphql/examples/blob/master/rocket/starwars/src/main.rs>)**
#![warn(missing_docs)]

View File

@ -233,6 +233,10 @@ pub enum ParseRequestError {
#[cfg_attr(feature = "nightly", doc(cfg(feature = "multipart")))]
InvalidMultipart(multer::Error),
/// The content type of the request was unknown.
#[error("Unknown content-type \"{0}\"")]
UnknownContentType(String),
/// Missing "operators" part for multipart request.
#[error("Missing \"operators\" part")]
MissingOperatorsPart,

View File

@ -38,8 +38,12 @@ pub async fn receive_batch_body(
body: impl AsyncRead + Send + 'static,
opts: MultipartOptions,
) -> Result<BatchRequest, ParseRequestError> {
let content_type = content_type.as_ref().map(AsRef::as_ref);
if let Some(Ok(boundary)) = content_type.map(multer::parse_boundary) {
multipart::receive_batch_multipart(body, boundary, opts).await
} else if let Some(content_type) = content_type.filter(|&ct| ct != "application/json") {
Err(ParseRequestError::UnknownContentType(content_type.to_owned()))
} else {
receive_batch_json(body).await
}