Set charset=utf-8 for better consistentcy

This commit is contained in:
Jarred Sumner
2022-03-18 20:18:58 -07:00
parent 20ec3d9bbd
commit 7dc76bf709
3 changed files with 14 additions and 6 deletions

View File

@@ -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);
});

View File

@@ -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);

View File

@@ -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;