mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
mark res.send ETag as weak and reduce collisions
This commit is contained in:
parent
1f2e00ef8d
commit
8ab96ab80d
|
|
@ -2,6 +2,7 @@
|
||||||
===
|
===
|
||||||
|
|
||||||
* Include ETag in HEAD requests
|
* Include ETag in HEAD requests
|
||||||
|
* mark `res.send` ETag as weak and reduce collisions
|
||||||
* update connect to 2.18.0
|
* update connect to 2.18.0
|
||||||
- deps: compression@1.0.3
|
- deps: compression@1.0.3
|
||||||
- deps: serve-index@1.1.0
|
- deps: serve-index@1.1.0
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,17 @@ exports.deprecate = function(fn, msg){
|
||||||
* Return ETag for `body`.
|
* Return ETag for `body`.
|
||||||
*
|
*
|
||||||
* @param {String|Buffer} body
|
* @param {String|Buffer} body
|
||||||
|
* @param {String} [encoding]
|
||||||
* @return {String}
|
* @return {String}
|
||||||
* @api private
|
* @api private
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.etag = function(body){
|
exports.etag = function(body, encoding){
|
||||||
return '"' + crc32.signed(body) + '"';
|
var buf = Buffer.isBuffer(body)
|
||||||
|
? body
|
||||||
|
: new Buffer(body, encoding)
|
||||||
|
var len = buf.length
|
||||||
|
return 'W/"' + len.toString(16) + '-' + crc32.unsigned(buf) + '"'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ describe('res', function(){
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('ETag', '"-1498647312"')
|
.expect('ETag', 'W/"7ff-2796319984"')
|
||||||
.end(done);
|
.end(done);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -194,7 +194,7 @@ describe('res', function(){
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
.expect('ETag', '"-1498647312"')
|
.expect('ETag', 'W/"7ff-2796319984"')
|
||||||
.end(done);
|
.end(done);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -309,7 +309,7 @@ describe('res', function(){
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
.set('If-None-Match', '"-1498647312"')
|
.set('If-None-Match', 'W/"7ff-2796319984"')
|
||||||
.expect(304, done);
|
.expect(304, done);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -358,7 +358,7 @@ describe('res', function(){
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should send ETag ', function(done){
|
it('should send ETag', function(done){
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
app.use(function(req, res){
|
app.use(function(req, res){
|
||||||
|
|
@ -368,10 +368,7 @@ describe('res', function(){
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
.get('/')
|
.get('/')
|
||||||
.end(function(err, res){
|
.expect('etag', 'W/"7ff-2796319984"', done)
|
||||||
res.headers.should.have.property('etag', '"-1498647312"');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,16 @@ describe('utils.etag(body)', function(){
|
||||||
var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';
|
var strUTF8 = '<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>';
|
||||||
|
|
||||||
it('should support strings', function(){
|
it('should support strings', function(){
|
||||||
utils.etag(str).should.eql('"-2034458343"');
|
utils.etag(str).should.eql('W/"9-2260508953"');
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support utf8 strings', function(){
|
it('should support utf8 strings', function(){
|
||||||
utils.etag(strUTF8).should.eql('"1395090196"');
|
utils.etag(strUTF8, 'utf8').should.eql('W/"4d-1395090196"');
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support buffer', function(){
|
it('should support buffer', function(){
|
||||||
utils.etag(new Buffer(strUTF8)).should.eql('"1395090196"');
|
utils.etag(new Buffer(strUTF8, 'utf8')).should.eql('W/"4d-1395090196"');
|
||||||
utils.etag(new Buffer(str)).should.eql('"-2034458343"');
|
utils.etag(new Buffer(str)).should.eql('W/"9-2260508953"');
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user