mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-28 00:00:20 +02:00
feat: default to charset=utf-8 for text content type (#554)
* feat: default to charset=utf-8 for text content type * added changelog && fix comment * fix workflow
This commit is contained in:
@@ -45,23 +45,22 @@ impl IntoResponse for ErasedJson {
|
||||
type BodyError = Infallible;
|
||||
|
||||
fn into_response(self) -> Response<Self::Body> {
|
||||
#[allow(clippy::declare_interior_mutable_const)]
|
||||
const APPLICATION_JSON: HeaderValue = HeaderValue::from_static("application/json");
|
||||
|
||||
let bytes = match self.0 {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
return Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.header(header::CONTENT_TYPE, "text/plain")
|
||||
.header(header::CONTENT_TYPE, mime::TEXT_PLAIN_UTF_8.as_ref())
|
||||
.body(Full::from(err.to_string()))
|
||||
.unwrap();
|
||||
}
|
||||
};
|
||||
|
||||
let mut res = Response::new(Full::from(bytes));
|
||||
res.headers_mut()
|
||||
.insert(header::CONTENT_TYPE, APPLICATION_JSON);
|
||||
res.headers_mut().insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static(mime::APPLICATION_JSON.as_ref()),
|
||||
);
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user