fix: fix build and gate cbor behind feature flag
This commit is contained in:
parent
ff0469a09f
commit
0c1d4963aa
|
@ -43,16 +43,6 @@ pub async fn receive_batch_body(
|
||||||
let content_type: mime::Mime = content_type.parse()?;
|
let content_type: mime::Mime = content_type.parse()?;
|
||||||
|
|
||||||
match (content_type.type_(), content_type.subtype()) {
|
match (content_type.type_(), content_type.subtype()) {
|
||||||
// application/json -> try json
|
|
||||||
(mime::APPLICATION, mime::JSON) => receive_batch_json(body).await,
|
|
||||||
|
|
||||||
// cbor is in application/octet-stream.
|
|
||||||
// TODO: wait for mime to add application/cbor and match against that too
|
|
||||||
#[cfg(feature = "cbor")]
|
|
||||||
(mime::OCTET_STREAM, _) | (mime::APPLICATION, mime::OCTET_STREAM) => {
|
|
||||||
receive_batch_cbor(body).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to use multipart
|
// try to use multipart
|
||||||
(mime::MULTIPART, _) => {
|
(mime::MULTIPART, _) => {
|
||||||
if let Some(boundary) = content_type.get_param("boundary") {
|
if let Some(boundary) = content_type.get_param("boundary") {
|
||||||
|
@ -65,11 +55,9 @@ pub async fn receive_batch_body(
|
||||||
}
|
}
|
||||||
// application/json or cbor (currently)
|
// application/json or cbor (currently)
|
||||||
// cbor is in application/octet-stream.
|
// cbor is in application/octet-stream.
|
||||||
|
// Note: cbor will only match if feature ``cbor`` is active
|
||||||
// TODO: wait for mime to add application/cbor and match against that too
|
// TODO: wait for mime to add application/cbor and match against that too
|
||||||
(mime::APPLICATION, mime::JSON)
|
_ => receive_batch_body_no_multipart(&content_type, body).await,
|
||||||
| (mime::OCTET_STREAM, _)
|
|
||||||
| (mime::APPLICATION, mime::OCTET_STREAM)
|
|
||||||
| _ => receive_batch_body_no_multipart(&content_type, body).await,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,13 +69,14 @@ pub(super) async fn receive_batch_body_no_multipart(
|
||||||
) -> Result<BatchRequest, ParseRequestError> {
|
) -> Result<BatchRequest, ParseRequestError> {
|
||||||
assert_ne!(content_type.type_(), mime::MULTIPART, "received multipart");
|
assert_ne!(content_type.type_(), mime::MULTIPART, "received multipart");
|
||||||
match (content_type.type_(), content_type.subtype()) {
|
match (content_type.type_(), content_type.subtype()) {
|
||||||
|
#[cfg(feature = "cbor")]
|
||||||
// cbor is in application/octet-stream.
|
// cbor is in application/octet-stream.
|
||||||
// TODO: wait for mime to add application/cbor and match against that too
|
// TODO: wait for mime to add application/cbor and match against that too
|
||||||
(mime::OCTET_STREAM, _) | (mime::APPLICATION, mime::OCTET_STREAM) => {
|
(mime::OCTET_STREAM, _) | (mime::APPLICATION, mime::OCTET_STREAM) => {
|
||||||
receive_batch_cbor(body).await
|
receive_batch_cbor(body).await
|
||||||
}
|
}
|
||||||
// application/json -> try json
|
// default to json
|
||||||
(mime::APPLICATION, mime::JSON) | _ => receive_batch_json(body).await,
|
_ => receive_batch_json(body).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Receive a GraphQL request from a body as JSON.
|
/// Receive a GraphQL request from a body as JSON.
|
||||||
|
|
|
@ -81,23 +81,25 @@ pub(super) async fn receive_batch_multipart(
|
||||||
}
|
}
|
||||||
Some("map") => {
|
Some("map") => {
|
||||||
let map_bytes = field.bytes().await?;
|
let map_bytes = field.bytes().await?;
|
||||||
// Note: we actually differ here from the inoffical spec for this:
|
|
||||||
// (https://github.com/jaydenseric/graphql-multipart-request-spec#multipart-form-field-structure)
|
|
||||||
// It says: "map: A JSON encoded map of where files occurred in the operations.
|
|
||||||
// For each file, the key is the file multipart form field name and the value is an array of operations paths."
|
|
||||||
// However, I think, that since we accepct CBOR as operation, which is valid, we should also accepct it
|
|
||||||
// as the mapping for the files.
|
|
||||||
match (content_type.type_(), content_type.subtype()) {
|
match (content_type.type_(), content_type.subtype()) {
|
||||||
// cbor is in application/octet-stream.
|
// cbor is in application/octet-stream.
|
||||||
// TODO: wait for mime to add application/cbor and match against that too
|
// TODO: wait for mime to add application/cbor and match against that too
|
||||||
|
// Note: we actually differ here from the inoffical spec for this:
|
||||||
|
// (https://github.com/jaydenseric/graphql-multipart-request-spec#multipart-form-field-structure)
|
||||||
|
// It says: "map: A JSON encoded map of where files occurred in the operations.
|
||||||
|
// For each file, the key is the file multipart form field name and the value is an array of operations paths."
|
||||||
|
// However, I think, that since we accepct CBOR as operation, which is valid, we should also accept it
|
||||||
|
// as the mapping for the files.
|
||||||
|
#[cfg(feature = "cbor")]
|
||||||
(mime::OCTET_STREAM, _) | (mime::APPLICATION, mime::OCTET_STREAM) => {
|
(mime::OCTET_STREAM, _) | (mime::APPLICATION, mime::OCTET_STREAM) => {
|
||||||
map = Some(
|
map = Some(
|
||||||
serde_cbor::from_slice::<HashMap<String, Vec<String>>>(&map_bytes)
|
serde_cbor::from_slice::<HashMap<String, Vec<String>>>(&map_bytes)
|
||||||
.map_err(|e| ParseRequestError::InvalidFilesMap(Box::new(e)))?,
|
.map_err(|e| ParseRequestError::InvalidFilesMap(Box::new(e)))?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// application/json -> try json
|
// default to json
|
||||||
(mime::APPLICATION, mime::JSON) | _ => {
|
_ => {
|
||||||
map = Some(
|
map = Some(
|
||||||
serde_json::from_slice::<HashMap<String, Vec<String>>>(&map_bytes)
|
serde_json::from_slice::<HashMap<String, Vec<String>>>(&map_bytes)
|
||||||
.map_err(|e| ParseRequestError::InvalidFilesMap(Box::new(e)))?,
|
.map_err(|e| ParseRequestError::InvalidFilesMap(Box::new(e)))?,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user