Skip to content
Myr

Handling invalid ranges

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

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent c3365aa · Browse files · 3 files+45 added−2 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+45 added−2 removed

  • tests:+38 added−0 removed
  • other:+7 added−2 removed

3 files+45 added−2 removed

modified:lib/express/response.js+1 added-1 removed
148 unmodified lines
149150 fs.stat(path, function(err, stat){151 if (err) return error(err);152 if (stat.size >= streamThreshold) {153 if (ranges) ranges = parseRange(stat.size, ranges);153 var status = 200;154 if (ranges) ranges = parseRange(stat.size, ranges);155 if (ranges) {156 var stream = fs.createReadStream(path, ranges[0]),157 start = ranges[0].start,158 end = ranges[0].end;
202 unmodified lines
modified:lib/express/utils.js+6 added-1 removed
modified:test/response.test.js+38 added
251 unmodified lines
252 'Content-Length': 500,253 'Content-Range': 'bytes 0-499/2535'254 }, status: 206 });255 },256257 'test #sendfile() Range invalid syntax': function(assert){258 var app = express.createServer();259 260 app.set('stream threshold', 1024);261 262 app.get('/*', function(req, res, next){263 var file = req.params[0],264 path = __dirname + '/fixtures/' + file;265 res.sendfile(path);266 });267268 assert.response(app,269 { url: '/large.json', headers: { 'Range': 'basdytes=asdf' }},270 { headers: {271 'Content-Type': 'application/json',272 'Content-Length': 2535273 }, status: 200 });274 },275 276 'test #sendfile() Range invalid range': function(assert){277 var app = express.createServer();278 279 app.set('stream threshold', 1024);280 281 app.get('/*', function(req, res, next){282 var file = req.params[0],283 path = __dirname + '/fixtures/' + file;284 res.sendfile(path);285 });286287 assert.response(app,288 { url: '/large.json', headers: { 'Range': 'bytes=500-10' }},289 { headers: {290 'Content-Type': 'application/json',291 'Content-Length': 2535292 }, status: 200 });293 },294 295 'test #download()': function(assert){296 var app = express.createServer();297
83 unmodified lines