mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Set charset=utf-8 for better consistentcy
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user