Skip to content

Commit e6845cc

Browse files
authored
Make Response::from_html use text/html; charset=utf-8 (#447)
* Make Response::from_html use `text/html; charset=utf-8` * Make Response::ok use `text/plain; charset=utf-8` * Fix code formatting
1 parent 3e302df commit e6845cc

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

examples/hyper/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ async fn make_request(
2020
.map_err(map_hyper_error)?;
2121
let text = std::str::from_utf8(&buf).map_err(map_utf8_error)?;
2222
let mut response = Response::ok(text)?;
23-
response.headers_mut().append("Content-Type", "text/html")?;
23+
response
24+
.headers_mut()
25+
.append("Content-Type", "text/html; charset=utf-8")?;
2426
Ok(response)
2527
}
2628
#[event(fetch)]

worker/src/response.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ impl Response {
5252
}
5353

5454
/// Create a `Response` using the body encoded as HTML. Sets the associated `Content-Type`
55-
/// header for the `Response` as `text/html`.
55+
/// header for the `Response` as `text/html; charset=utf-8`.
5656
pub fn from_html(html: impl AsRef<str>) -> Result<Self> {
5757
let mut headers = Headers::new();
58-
headers.set(CONTENT_TYPE, "text/html")?;
58+
headers.set(CONTENT_TYPE, "text/html; charset=utf-8")?;
5959

6060
let data = html.as_ref().as_bytes().to_vec();
6161
Ok(Self {
@@ -130,10 +130,10 @@ impl Response {
130130
}
131131

132132
/// Create a `Response` using unprocessed text provided. Sets the associated `Content-Type`
133-
/// header for the `Response` as `text/plain`.
133+
/// header for the `Response` as `text/plain; charset=utf-8`.
134134
pub fn ok(body: impl Into<String>) -> Result<Self> {
135135
let mut headers = Headers::new();
136-
headers.set(CONTENT_TYPE, "text/plain")?;
136+
headers.set(CONTENT_TYPE, "text/plain; charset=utf-8")?;
137137

138138
Ok(Self {
139139
body: ResponseBody::Body(body.into().into_bytes()),

0 commit comments

Comments
 (0)