Skip to content

Commit 8d654a6

Browse files
authored
Fix Content-Type header parsing in 'juniper_actix' (#863, #860)
1 parent 824cd40 commit 8d654a6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

juniper_actix/src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Check the LICENSE file for details.
4242

4343
use actix_web::{
4444
error::{ErrorBadRequest, ErrorMethodNotAllowed, ErrorUnsupportedMediaType},
45-
http::{header::CONTENT_TYPE, Method},
46-
web, Error, FromRequest, HttpRequest, HttpResponse,
45+
http::Method,
46+
web, Error, FromRequest, HttpMessage, HttpRequest, HttpResponse,
4747
};
4848
use juniper::{
4949
http::{
@@ -152,16 +152,12 @@ where
152152
CtxT: Sync,
153153
S: ScalarValue + Send + Sync,
154154
{
155-
let content_type_header = req
156-
.headers()
157-
.get(CONTENT_TYPE)
158-
.and_then(|hv| hv.to_str().ok());
159-
let req = match content_type_header {
160-
Some("application/json") => {
155+
let req = match req.content_type() {
156+
"application/json" => {
161157
let body = String::from_request(&req, &mut payload.into_inner()).await?;
162158
serde_json::from_str::<GraphQLBatchRequest<S>>(&body).map_err(ErrorBadRequest)
163159
}
164-
Some("application/graphql") => {
160+
"application/graphql" => {
165161
let body = String::from_request(&req, &mut payload.into_inner()).await?;
166162
Ok(GraphQLBatchRequest::Single(GraphQLRequest::new(
167163
body, None, None,
@@ -609,7 +605,7 @@ mod tests {
609605
);
610606

611607
let req = test::TestRequest::post()
612-
.header("content-type", "application/json")
608+
.header("content-type", "application/json; charset=utf-8")
613609
.set_payload(
614610
r##"{ "variables": null, "query": "{ hero(episode: NEW_HOPE) { name } }" }"##,
615611
)

0 commit comments

Comments
 (0)