aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-18 20:18:58 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-18 20:18:58 -0700
commit7dc76bf70902de10cb4f4752dae4c7e90cfc1027 (patch)
tree3cf1d033aec0f800f0093834d05fb8b485f0333d
parent20ec3d9bbda91495b84ea8caaa71178c40340f35 (diff)
downloadbun-7dc76bf70902de10cb4f4752dae4c7e90cfc1027.tar.gz
bun-7dc76bf70902de10cb4f4752dae4c7e90cfc1027.tar.zst
bun-7dc76bf70902de10cb4f4752dae4c7e90cfc1027.zip
Set charset=utf-8 for better consistentcy
-rw-r--r--integration/bunjs-only-snippets/fetch.test.js16
-rw-r--r--src/http/mime_type.zig2
-rw-r--r--src/javascript/jsc/webcore/response.zig2
3 files changed, 14 insertions, 6 deletions
diff --git a/integration/bunjs-only-snippets/fetch.test.js b/integration/bunjs-only-snippets/fetch.test.js
index 87cd5414f..b1ab57366 100644
--- a/integration/bunjs-only-snippets/fetch.test.js
+++ b/integration/bunjs-only-snippets/fetch.test.js
@@ -280,13 +280,17 @@ describe("Response", () => {
it("sets the content-type header", () => {
let response = Response.json("hello");
expect(response.type).toBe("basic");
- expect(response.headers.get("content-type")).toBe("application/json");
+ expect(response.headers.get("content-type")).toBe(
+ "application/json;charset=utf-8"
+ );
expect(response.status).toBe(200);
});
it("supports number status code", () => {
let response = Response.json("hello", 407);
expect(response.type).toBe("basic");
- expect(response.headers.get("content-type")).toBe("application/json");
+ expect(response.headers.get("content-type")).toBe(
+ "application/json;charset=utf-8"
+ );
expect(response.status).toBe(407);
});
it("overrides the content-type header", () => {
@@ -296,7 +300,9 @@ describe("Response", () => {
},
});
expect(response.type).toBe("basic");
- expect(response.headers.get("content-type")).toBe("application/json");
+ expect(response.headers.get("content-type")).toBe(
+ "application/json;charset=utf-8"
+ );
});
it("supports headers", () => {
var response = Response.json("hello", {
@@ -306,7 +312,9 @@ describe("Response", () => {
},
statusCode: 408,
});
- expect(response.headers.get("content-type")).toBe("application/json");
+ expect(response.headers.get("content-type")).toBe(
+ "application/json;charset=utf-8"
+ );
expect(response.headers.get("x-hello")).toBe("world");
expect(response.status).toBe(408);
});
diff --git a/src/http/mime_type.zig b/src/http/mime_type.zig
index 65dd367cd..dfaa8f7e9 100644
--- a/src/http/mime_type.zig
+++ b/src/http/mime_type.zig
@@ -63,7 +63,7 @@ pub const javascript = MimeType.initComptime("text/javascript;charset=utf-8", .j
pub const ico = MimeType.initComptime("image/vnd.microsoft.icon", .image);
pub const html = MimeType.initComptime("text/html;charset=utf-8", .html);
// we transpile json to javascript so that it is importable without import assertions.
-pub const json = MimeType.initComptime("application/json", .json);
+pub const json = MimeType.initComptime("application/json;charset=utf-8", .json);
pub const transpiled_json = javascript;
pub const text = MimeType.initComptime("text/plain;charset=utf-8", .html);
diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig
index 41f08cce4..721ffc5ca 100644
--- a/src/javascript/jsc/webcore/response.zig
+++ b/src/javascript/jsc/webcore/response.zig
@@ -392,7 +392,7 @@ pub const Response = struct {
}
var headers_ref = response.getOrCreateHeaders().leak();
- headers_ref.putHeaderNormalized("content-type", "application/json", false);
+ headers_ref.putHeaderNormalized("content-type", MimeType.json.value, false);
var ptr = response.allocator.create(Response) catch unreachable;
ptr.* = response;