Pass options from res.sendfile to send

fixes #2017
This commit is contained in:
Douglas Christopher Wilson 2014-04-24 15:17:22 -04:00
parent 8ccceacf91
commit 2fd3e72a19
3 changed files with 32 additions and 3 deletions

View File

@ -256,6 +256,9 @@ res.jsonp = function(obj){
*
* - `maxAge` defaulting to 0
* - `root` root directory for relative filenames
* - `hidden` serve hidden files, defaulting to false
*
* Other options are passed along to `send`.
*
* Examples:
*
@ -331,10 +334,11 @@ res.sendfile = function(path, options, fn){
req.socket.removeListener('error', error);
}
// Back-compat
options.maxage = options.maxage || options.maxAge || 0;
// transfer
var file = send(req, path);
if (options.root) file.root(options.root);
file.maxage(options.maxAge || 0);
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

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