Skip to content

Commit 3724019

Browse files
refactor: add charset when serving the bundle files
Reference: https://developer.mozilla.org/fr/docs/Web/HTTP/Headers/Content-Type Related: socketio#4589
1 parent e1b4f61 commit 3724019

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ export class Server<
488488
res.writeHeader("cache-control", "public, max-age=0");
489489
res.writeHeader(
490490
"content-type",
491-
"application/" + (isMap ? "json" : "javascript")
491+
"application/" + (isMap ? "json" : "javascript") + "; charset=utf-8"
492492
);
493493
res.writeHeader("etag", expectedEtag);
494494

@@ -581,7 +581,7 @@ export class Server<
581581
res.setHeader("Cache-Control", "public, max-age=0");
582582
res.setHeader(
583583
"Content-Type",
584-
"application/" + (isMap ? "json" : "javascript")
584+
"application/" + (isMap ? "json" : "javascript") + "; charset=utf-8"
585585
);
586586
res.setHeader("ETag", expectedEtag);
587587

test/server-attachment.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ describe("server attachment", () => {
1616
.buffer(true)
1717
.end((err, res) => {
1818
if (err) return done(err);
19-
expect(res.headers["content-type"]).to.be("application/javascript");
19+
expect(res.headers["content-type"]).to.be(
20+
"application/javascript; charset=utf-8"
21+
);
2022
expect(res.headers.etag).to.be('"' + clientVersion + '"');
2123
expect(res.headers["x-sourcemap"]).to.be(undefined);
2224
expect(res.text).to.match(/engine\.io/);
@@ -33,7 +35,9 @@ describe("server attachment", () => {
3335
.buffer(true)
3436
.end((err, res) => {
3537
if (err) return done(err);
36-
expect(res.headers["content-type"]).to.be("application/json");
38+
expect(res.headers["content-type"]).to.be(
39+
"application/json; charset=utf-8"
40+
);
3741
expect(res.headers.etag).to.be('"' + clientVersion + '"');
3842
expect(res.text).to.match(/engine\.io/);
3943
expect(res.status).to.be(200);

test/uws.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ describe("socket.io with uWebSocket.js-based engine", () => {
200200
.buffer(true)
201201
.end((err, res) => {
202202
if (err) return done(err);
203-
expect(res.headers["content-type"]).to.be("application/javascript");
203+
expect(res.headers["content-type"]).to.be(
204+
"application/javascript; charset=utf-8"
205+
);
204206
expect(res.headers.etag).to.be('"' + clientVersion + '"');
205207
expect(res.headers["x-sourcemap"]).to.be(undefined);
206208
expect(res.text).to.match(/engine\.io/);

0 commit comments

Comments
 (0)