Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[assets] confirm a weak but matching ETag #3485

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/index.js
Expand Up @@ -358,10 +358,11 @@ Server.prototype.serve = function(req, res){
// Per the standard, ETags must be quoted:
// https://tools.ietf.org/html/rfc7232#section-2.3
var expectedEtag = '"' + clientVersion + '"';
var weakEtag = 'W/' + expectedEtag;

var etag = req.headers['if-none-match'];
if (etag) {
if (expectedEtag == etag) {
if (expectedEtag == etag || weakEtag == etag) {
debug('serve client 304');
res.writeHead(304);
res.end();
Expand Down
13 changes: 13 additions & 0 deletions test/socket.io.js
Expand Up @@ -182,6 +182,19 @@ describe('socket.io', function(){
});
});

it('should handle 304 from weak etag', function(done){
var srv = http();
io(srv);
request(srv)
.get('/socket.io/socket.io.js')
.set('If-None-Match', 'W/"' + clientVersion + '"')
.end(function(err, res){
if (err) return done(err);
expect(res.statusCode).to.be(304);
done();
});
});

it('should not serve static files', function(done){
var srv = http();
io(srv, { serveClient: false });
Expand Down