Browse files

when syntactically invalid Range should be ignored

  • Loading branch information...
1 parent e44013c commit b61f42bbc19f0e3dd03d0b366e5543c12834ad24 @tj tj committed Feb 29, 2012
Showing with 17 additions and 18 deletions.
  1. +14 −15 lib/middleware/static.js
  2. +1 −1 lib/utils.js
  3. +2 −2 test/static.js
View
29 lib/middleware/static.js
@@ -188,22 +188,21 @@ var send = exports.send = function(req, res, next, options){
if (ranges) {
ranges = utils.parseRange(len, ranges);
- // invalid
- if (!ranges) return next(utils.error(416));
-
// valid
- // TODO: stream options
- // TODO: multiple support
- opts.start = ranges[0].start;
- opts.end = ranges[0].end;
- len = opts.end - opts.start + 1;
- res.statusCode = 206;
- res.setHeader('Content-Range', 'bytes '
- + opts.start
- + '-'
- + opts.end
- + '/'
- + stat.size);
+ if (ranges) {
+ // TODO: stream options
+ // TODO: multiple support
+ opts.start = ranges[0].start;
+ opts.end = ranges[0].end;
+ len = opts.end - opts.start + 1;
+ res.statusCode = 206;
+ res.setHeader('Content-Range', 'bytes '
+ + opts.start
+ + '-'
+ + opts.end
+ + '/'
+ + stat.size);
+ }
}
res.setHeader('Content-Length', len);
View
2 lib/utils.js
@@ -450,7 +450,7 @@ exports.parseRange = function(size, str){
};
});
- return valid ? arr : undefined;
+ return valid ? arr : null;
};
/**
View
4 test/static.js
@@ -174,11 +174,11 @@ describe('connect.static()', function(){
// TODO: multiple ranges
describe('when syntactically invalid', function(){
- it('should respond with 416 Request Range Not Satisfiable', function(done){
+ it('should respond with 200 and the entire contents', function(done){
app.request()
.get('/nums')
.set('Range', 'bytes=4-0')
- .expect(416, done);
+ .expect('123456789', done);
})
})
})

0 comments on commit b61f42b

Please sign in to comment.