@@ -6,7 +6,7 @@ use axum::{
66 async_trait,
77 body:: Body ,
88 extract:: { FromRequest , FromRequestParts , Query } ,
9- http:: { HeaderValue , Method , Request , StatusCode } ,
9+ http:: { header , HeaderValue , Method , Request , StatusCode } ,
1010 response:: { IntoResponse as _, Response } ,
1111 Json , RequestExt as _,
1212} ;
8585 async fn from_request ( mut req : Request < Body > , state : & State ) -> Result < Self , Self :: Rejection > {
8686 let content_type = req
8787 . headers ( )
88- . get ( "content-type" )
88+ . get ( header :: CONTENT_TYPE )
8989 . map ( HeaderValue :: to_str)
9090 . transpose ( )
9191 . map_err ( |_| {
@@ -122,22 +122,24 @@ where
122122 . into_response ( )
123123 } )
124124 } ) ,
125- ( & Method :: POST , Some ( "application/json" ) ) => {
125+ ( & Method :: POST , Some ( x ) ) if x . starts_with ( "application/json" ) => {
126126 Json :: < GraphQLBatchRequest < S > > :: from_request ( req, state)
127127 . await
128128 . map ( |req| Self ( req. 0 ) )
129129 . map_err ( |e| {
130130 ( StatusCode :: BAD_REQUEST , format ! ( "Invalid JSON body: {e}" ) ) . into_response ( )
131131 } )
132132 }
133- ( & Method :: POST , Some ( "application/graphql" ) ) => String :: from_request ( req, state)
134- . await
135- . map ( |body| {
136- Self ( GraphQLBatchRequest :: Single ( GraphQLRequest :: new (
137- body, None , None ,
138- ) ) )
139- } )
140- . map_err ( |_| ( StatusCode :: BAD_REQUEST , "Not valid UTF-8 body" ) . into_response ( ) ) ,
133+ ( & Method :: POST , Some ( x) ) if x. starts_with ( "application/graphql" ) => {
134+ String :: from_request ( req, state)
135+ . await
136+ . map ( |body| {
137+ Self ( GraphQLBatchRequest :: Single ( GraphQLRequest :: new (
138+ body, None , None ,
139+ ) ) )
140+ } )
141+ . map_err ( |_| ( StatusCode :: BAD_REQUEST , "Not valid UTF-8 body" ) . into_response ( ) )
142+ }
141143 ( & Method :: POST , _) => Err ( (
142144 StatusCode :: UNSUPPORTED_MEDIA_TYPE ,
143145 "`Content-Type` header is expected to be either `application/json` or \
0 commit comments