Pass options from res.sendfile to send

fixes #2017
This commit is contained in:
Douglas Christopher Wilson
2014-07-23 00:08:15 -04:00
parent 323c185079
commit 0d77305a1a
4 changed files with 32 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
3.x
===
* Pass options from `res.sendfile` to `send`
* deps: connect@2.24.0
- deps: body-parser@~1.5.0
- deps: compression@~1.0.9

View File

@@ -310,6 +310,9 @@ res.jsonp = function(obj){
*
* - `maxAge` defaulting to 0
* - `root` root directory for relative filenames
* - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them
*
* Other options are passed along to `send`.
*
* Examples:
*
@@ -385,10 +388,7 @@ res.sendfile = function(path, options, fn){
}
// transfer
var file = send(req, path, {
maxAge: options.maxAge || 0,
root: options.root
});
var file = send(req, path, options);
file.on('error', error);
file.on('directory', next);
file.on('stream', stream);

1
test/fixtures/.name vendored Normal file
View File

@@ -0,0 +1 @@
tobi

View File

@@ -106,6 +106,30 @@ describe('res', function(){
})
describe('.sendfile(path)', function(){
it('should not serve dotfiles', function(done){
var app = express();
app.use(function(req, res){
res.sendfile('test/fixtures/.name');
});
request(app)
.get('/')
.expect(404, done);
})
it('should accept dotfiles option', function(done){
var app = express();
app.use(function(req, res){
res.sendfile('test/fixtures/.name', { dotfiles: 'allow' });
});
request(app)
.get('/')
.expect(200, 'tobi', done);
})
describe('with an absolute path', function(){
it('should transfer the file', function(done){
var app = express();