Skip to content

Commit 023dcaf

Browse files
committed
feat(core): add charset parameter to HTML response header
1 parent 331b758 commit 023dcaf

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/core/src/http/common.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ export const jsonResponse = (value: JsonSerializable): ToHttpResponse => ({
5353
/**
5454
* An HTML response with the content-type header set to text/html.
5555
*/
56-
export const htmlResponse = (html: string): ToHttpResponse => ({
56+
export const htmlResponse = (html: string, charset = "utf-8"): ToHttpResponse => ({
5757
[TO_HTTP_RESPONSE]: (): HttpResponse => {
58-
return HttpResponse.builder().header("content-type", "text/html").body(html);
58+
return HttpResponse.builder()
59+
.header("content-type", `text/html; charset=${charset}`)
60+
.body(html);
5961
},
6062
});
6163

packages/core/test/http/common.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("http:common", () => {
3737
const html = "<h1>Hello</h1>";
3838
const res = htmlResponse(html)[TO_HTTP_RESPONSE]();
3939
assert.equal(res.status.code, 200);
40-
assert.equal(res.headers.get("content-type")?.value, "text/html");
40+
assert.equal(res.headers.get("content-type")?.value, "text/html; charset=utf-8");
4141

4242
const body = await consumers.text(res.body.readable);
4343
assert.equal(body, html);

0 commit comments

Comments
 (0)