diff --git a/History.md b/History.md index 872e6ced..e16e92ba 100644 --- a/History.md +++ b/History.md @@ -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 diff --git a/lib/response.js b/lib/response.js index fd031858..61c7f16c 100644 --- a/lib/response.js +++ b/lib/response.js @@ -308,8 +308,11 @@ res.jsonp = function(obj){ * * Options: * - * - `maxAge` defaulting to 0 - * - `root` root directory for relative filenames + * - `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); diff --git a/test/fixtures/.name b/test/fixtures/.name new file mode 100644 index 00000000..fa66f37f --- /dev/null +++ b/test/fixtures/.name @@ -0,0 +1 @@ +tobi \ No newline at end of file diff --git a/test/res.sendfile.js b/test/res.sendfile.js index 8603f205..27ffba69 100644 --- a/test/res.sendfile.js +++ b/test/res.sendfile.js @@ -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();