Skip to content

Commit 44b90d9

Browse files
authored
fix: add json mime type to response header (#21)
1 parent ba0eb69 commit 44b90d9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ tokio-util = { version = "0.7.13", optional = true, features = ["io", "rt"] }
3636
# ws
3737
tokio-tungstenite = { version = "0.26.1", features = ["rustls-tls-webpki-roots"], optional = true }
3838
futures-util = { version = "0.3.31", optional = true }
39+
mime = "0.3.17"
3940

4041
[dev-dependencies]
4142
tempfile = "3.15.0"

src/axum.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ use crate::{
22
types::{InboundData, Response},
33
HandlerCtx, TaskSet,
44
};
5-
use axum::{extract::FromRequest, response::IntoResponse};
5+
use axum::{
6+
extract::FromRequest,
7+
http::{header, HeaderValue},
8+
response::IntoResponse,
9+
};
610
use bytes::Bytes;
711
use std::{future::Future, pin::Pin};
812
use tokio::runtime::Handle;
@@ -66,7 +70,12 @@ where
6670
.call_batch_with_state(self.ctx(), req, state)
6771
.await
6872
{
69-
Box::<str>::from(response).into_response()
73+
let headers = [(
74+
header::CONTENT_TYPE,
75+
HeaderValue::from_static(mime::APPLICATION_JSON.as_ref()),
76+
)];
77+
let body = Box::<str>::from(response);
78+
(headers, body).into_response()
7079
} else {
7180
().into_response()
7281
}

0 commit comments

Comments
 (0)