Skip to content

Commit

Permalink
refactor: add cache-control header in the polling response
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Oct 5, 2023
1 parent ff1c861 commit 505ce8c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/transports-uws/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ export class Polling extends Transport {
headers["X-XSS-Protection"] = "0";
}

headers["cache-control"] = "no-store";

this.emit("headers", headers, req);
return headers;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/transports/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ export class Polling extends Transport {
headers["X-XSS-Protection"] = "0";
}

headers["cache-control"] = "no-store";

this.emit("headers", headers, req);
return headers;
}
Expand Down
22 changes: 17 additions & 5 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3443,13 +3443,12 @@ describe("server", () => {
});

describe("response headers", () => {
function testForHeaders(headers, done) {
function testForHeaders(headers, callback) {
const engine = listen((port) => {
engine.on("connection", (conn) => {
conn.transport.once("headers", (headers) => {
expect(headers["X-XSS-Protection"]).to.be("0");
callback(headers);
conn.close();
done();
});
conn.send("hi");
});
Expand All @@ -3465,15 +3464,28 @@ describe("server", () => {
"user-agent":
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Tablet PC 2.0)",
};
testForHeaders(headers, done);
testForHeaders(headers, (headers) => {
expect(headers["X-XSS-Protection"]).to.be("0");
done();
});
});

it("should contain X-XSS-Protection: 0 for IE11", (done) => {
const headers = {
"user-agent":
"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko",
};
testForHeaders(headers, done);
testForHeaders(headers, (headers) => {
expect(headers["X-XSS-Protection"]).to.be("0");
done();
});
});

it("should include a 'cache-control' header", (done) => {
testForHeaders({}, (headers) => {
expect(headers["cache-control"]).to.be("no-store");
done();
});
});

it("should emit a 'initial_headers' event (polling)", (done) => {
Expand Down

0 comments on commit 505ce8c

Please sign in to comment.