Skip to content

Commit 161091d

Browse files
das7paddarrachequesne
authored andcommitted
feat: confirm a weak but matching ETag (#3485)
When handling compression at the proxy server level, the client receives a weak ETag. Weak ETags are prefixed with `W/`, e.g. `W/"2.2.0"`. Upon cache validation we should take care of these too. Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
1 parent d52532b commit 161091d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,11 @@ export class Server extends EventEmitter {
437437
// Per the standard, ETags must be quoted:
438438
// https://tools.ietf.org/html/rfc7232#section-2.3
439439
const expectedEtag = '"' + clientVersion + '"';
440+
const weakEtag = "W/" + expectedEtag;
440441

441442
const etag = req.headers["if-none-match"];
442443
if (etag) {
443-
if (expectedEtag == etag) {
444+
if (expectedEtag === etag || weakEtag === etag) {
444445
debug("serve client %s 304", type);
445446
res.writeHead(304);
446447
res.end();

test/socket.io.ts

+13
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ describe("socket.io", () => {
128128
});
129129
});
130130

131+
it("should handle 304", (done) => {
132+
const srv = createServer();
133+
new Server(srv);
134+
request(srv)
135+
.get("/socket.io/socket.io.js")
136+
.set("If-None-Match", 'W/"' + clientVersion + '"')
137+
.end((err, res) => {
138+
if (err) return done(err);
139+
expect(res.statusCode).to.be(304);
140+
done();
141+
});
142+
});
143+
131144
it("should not serve static files", (done) => {
132145
const srv = createServer();
133146
new Server(srv, { serveClient: false });

0 commit comments

Comments
 (0)