mirror of https://github.com/fafhrd91/actix-web
Let ResponseError render w/ 'text/plain; charset=utf-8' header (#1118)
Trait ResponseError originally render Error messages with header `text/plain` , which causes browsers (i.e. Firefox 70.0) with Non-English locale unable to render UTF-8 responses with non-English characters correctly. i.e. emoji. This fix solved this problem by specifying the charset of `text/plain` as utf-8, which is the default charset in rust. Before actix-web consider to support other charsets, this hotfix is enough. Test case: fn test() -> Result<String, actix_web::Error> { Err(actix_web::error::ErrorForbidden("ðtest")) }
This commit is contained in:
parent
fba31d4e0a
commit
554e2e6799
|
@ -75,7 +75,7 @@ pub trait ResponseError: fmt::Debug + fmt::Display {
|
||||||
let _ = write!(Writer(&mut buf), "{}", self);
|
let _ = write!(Writer(&mut buf), "{}", self);
|
||||||
resp.headers_mut().insert(
|
resp.headers_mut().insert(
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
header::HeaderValue::from_static("text/plain"),
|
header::HeaderValue::from_static("text/plain; charset=utf-8"),
|
||||||
);
|
);
|
||||||
resp.set_body(Body::from(buf))
|
resp.set_body(Body::from(buf))
|
||||||
}
|
}
|
||||||
|
@ -536,7 +536,7 @@ where
|
||||||
let _ = write!(Writer(&mut buf), "{}", self);
|
let _ = write!(Writer(&mut buf), "{}", self);
|
||||||
res.headers_mut().insert(
|
res.headers_mut().insert(
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
header::HeaderValue::from_static("text/plain"),
|
header::HeaderValue::from_static("text/plain; charset=utf-8"),
|
||||||
);
|
);
|
||||||
res.set_body(Body::from(buf))
|
res.set_body(Body::from(buf))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue