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:
Pure White
2021-11-25 08:31:30 +00:00
committed by GitHub
parent c5a33addb7
commit 5a5800c1ae
13 changed files with 54 additions and 44 deletions
+5 -6
View File
@@ -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
}
}