Skip to content
Myr

Fix TypeError in res.send when given Buffer and ETag header set

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fixes #3445

authored by David Wood · committed by Douglas Christopher Wilson · parent 48aba21 · Browse files · 3 files+23 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+23 added−5 removed

  • tests:+13 added−0 removed
  • other:+10 added−5 removed

3 files+23 added−5 removed

modified:lib/response.js+5 added-5 removed
176 unmodified lines
177178 // populate Content-Length179 var len180 if (chunk !== undefined) {181 if (Buffer.isBuffer(chunk)) {182 // get length of Buffer183 len = chunk.length181 if (!generateETag && chunk.length < 1000) {184 } else if (!generateETag && chunk.length < 1000) {185 // just calculate length when no ETag + small chunk186 len = Buffer.byteLength(chunk, encoding)184 } else if (!Buffer.isBuffer(chunk)) {187 } else {188 // convert chunk to Buffer and calculate189 chunk = Buffer.from(chunk, encoding)190 encoding = undefined;191 len = chunk.length189 } else {190 // get length of Buffer191 len = chunk.length192 }193194 this.set('Content-Length', len);195 }
942 unmodified lines
modified:test/res.send.js+13 added
214 unmodified lines
215 .get('/')216 .expect('Content-Type', 'text/plain; charset=utf-8')217 .expect(200, 'hey', done);218 })219220 it('should not override ETag', function (done) {221 var app = express()222223 app.use(function (req, res) {224 res.type('text/plain').set('ETag', '"foo"').send(Buffer.from('hey'))225 })226227 request(app)228 .get('/')229 .expect('ETag', '"foo"')230 .expect(200, 'hey', done)231 })232 })233234 describe('.send(Object)', function(){235 it('should send as application/json', function(done){
327 unmodified lines
modified:History.md+5 added
1unreleased2==========34 * Fix `TypeError` in `res.send` when given `Buffer` and `ETag` header set564.16.1 / 2017-09-297===================89 * deps: send@0.16.1
3364 unmodified lines