Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Response::from_html use text/html; charset=utf-8 #447

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/hyper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn make_request(
.map_err(map_hyper_error)?;
let text = std::str::from_utf8(&buf).map_err(map_utf8_error)?;
let mut response = Response::ok(text)?;
response.headers_mut().append("Content-Type", "text/html")?;
response.headers_mut().append("Content-Type", "text/html; charset=utf-8")?;
Ok(response)
}
#[event(fetch)]
Expand Down
8 changes: 4 additions & 4 deletions worker/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ impl Response {
}

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

let data = html.as_ref().as_bytes().to_vec();
Ok(Self {
Expand Down Expand Up @@ -130,10 +130,10 @@ impl Response {
}

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

Ok(Self {
body: ResponseBody::Body(body.into().into_bytes()),
Expand Down
Loading