Skip to content

Commit 7f876d4

Browse files
authored
Remove redundant charset from application/json content type response header (#5779)
`application/json` is defined as unicode (see https://www.ietf.org/rfc/rfc4627.txt) and the media type has no `charset` support defined for it (see https://www.iana.org/assignments/media-types/application/json) also, this makes the header compatible with what `axum` sends by default... 😅
1 parent fe74dfe commit 7f876d4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/tests/util/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ where
9090
.get(header::CONTENT_TYPE)
9191
.expect("Missing content-type header");
9292

93-
assert_eq!(content_type, "application/json; charset=utf-8");
93+
assert_eq!(content_type, "application/json");
9494

9595
let content_length: usize = r
9696
.headers()

src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub type EndpointResult = Result<AppResponse, Box<dyn errors::AppError>>;
2727
pub fn json_response<T: Serialize>(t: &T) -> AppResponse {
2828
let json = serde_json::to_string(t).unwrap();
2929
Response::builder()
30-
.header(header::CONTENT_TYPE, "application/json; charset=utf-8")
30+
.header(header::CONTENT_TYPE, "application/json")
3131
.header(header::CONTENT_LENGTH, json.len())
3232
.body(Body::from_vec(json.into_bytes()))
3333
.unwrap() // Header values are well formed, so should not panic

0 commit comments

Comments
 (0)