Skip to content

Commit 9545b44

Browse files
refactor: add cache-control header in the polling response
This header should not be needed since the client already includes a cache busting query parameter ("t"), but a misconfigured CDN could ignore the query parameters and cache the server response. Related: socketio/socket.io#4842
1 parent ff1c861 commit 9545b44

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

lib/transports-uws/polling.ts

+2
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ export class Polling extends Transport {
423423
headers["X-XSS-Protection"] = "0";
424424
}
425425

426+
headers["cache-control"] = "no-store";
427+
426428
this.emit("headers", headers, req);
427429
return headers;
428430
}

lib/transports/polling.ts

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ export class Polling extends Transport {
392392
headers["X-XSS-Protection"] = "0";
393393
}
394394

395+
headers["cache-control"] = "no-store";
396+
395397
this.emit("headers", headers, req);
396398
return headers;
397399
}

test/server.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -3443,13 +3443,12 @@ describe("server", () => {
34433443
});
34443444

34453445
describe("response headers", () => {
3446-
function testForHeaders(headers, done) {
3446+
function testForHeaders(headers, callback) {
34473447
const engine = listen((port) => {
34483448
engine.on("connection", (conn) => {
34493449
conn.transport.once("headers", (headers) => {
3450-
expect(headers["X-XSS-Protection"]).to.be("0");
3450+
callback(headers);
34513451
conn.close();
3452-
done();
34533452
});
34543453
conn.send("hi");
34553454
});
@@ -3465,15 +3464,28 @@ describe("server", () => {
34653464
"user-agent":
34663465
"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)",
34673466
};
3468-
testForHeaders(headers, done);
3467+
testForHeaders(headers, (headers) => {
3468+
expect(headers["X-XSS-Protection"]).to.be("0");
3469+
done();
3470+
});
34693471
});
34703472

34713473
it("should contain X-XSS-Protection: 0 for IE11", (done) => {
34723474
const headers = {
34733475
"user-agent":
34743476
"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko",
34753477
};
3476-
testForHeaders(headers, done);
3478+
testForHeaders(headers, (headers) => {
3479+
expect(headers["X-XSS-Protection"]).to.be("0");
3480+
done();
3481+
});
3482+
});
3483+
3484+
it("should include a 'cache-control' header", (done) => {
3485+
testForHeaders({}, (headers) => {
3486+
expect(headers["cache-control"]).to.be("no-store");
3487+
done();
3488+
});
34773489
});
34783490

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

0 commit comments

Comments
 (0)