Skip to content

Commit

Permalink
refactor: add charset when serving the bundle files
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Jan 23, 2023
1 parent 184f3cf commit 93d446a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export class Server<
res.writeHeader("cache-control", "public, max-age=0");
res.writeHeader(
"content-type",
"application/" + (isMap ? "json" : "javascript")
"application/" + (isMap ? "json" : "javascript") + "; charset=utf-8"
);
res.writeHeader("etag", expectedEtag);

Expand Down Expand Up @@ -581,7 +581,7 @@ export class Server<
res.setHeader("Cache-Control", "public, max-age=0");
res.setHeader(
"Content-Type",
"application/" + (isMap ? "json" : "javascript")
"application/" + (isMap ? "json" : "javascript") + "; charset=utf-8"
);
res.setHeader("ETag", expectedEtag);

Expand Down
8 changes: 6 additions & 2 deletions test/server-attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ describe("server attachment", () => {
.buffer(true)
.end((err, res) => {
if (err) return done(err);
expect(res.headers["content-type"]).to.be("application/javascript");
expect(res.headers["content-type"]).to.be(
"application/javascript; charset=utf-8"
);
expect(res.headers.etag).to.be('"' + clientVersion + '"');
expect(res.headers["x-sourcemap"]).to.be(undefined);
expect(res.text).to.match(/engine\.io/);
Expand All @@ -33,7 +35,9 @@ describe("server attachment", () => {
.buffer(true)
.end((err, res) => {
if (err) return done(err);
expect(res.headers["content-type"]).to.be("application/json");
expect(res.headers["content-type"]).to.be(
"application/json; charset=utf-8"
);
expect(res.headers.etag).to.be('"' + clientVersion + '"');
expect(res.text).to.match(/engine\.io/);
expect(res.status).to.be(200);
Expand Down
4 changes: 3 additions & 1 deletion test/uws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ describe("socket.io with uWebSocket.js-based engine", () => {
.buffer(true)
.end((err, res) => {
if (err) return done(err);
expect(res.headers["content-type"]).to.be("application/javascript");
expect(res.headers["content-type"]).to.be(
"application/javascript; charset=utf-8"
);
expect(res.headers.etag).to.be('"' + clientVersion + '"');
expect(res.headers["x-sourcemap"]).to.be(undefined);
expect(res.text).to.match(/engine\.io/);
Expand Down

0 comments on commit 93d446a

Please sign in to comment.