Skip to content

Commit 0d77305

Browse files
committed
Pass options from res.sendfile to send
fixes expressjs#2017
1 parent 323c185 commit 0d77305

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
3.x
22
===
33

4+
* Pass options from `res.sendfile` to `send`
45
56
- deps: body-parser@~1.5.0
67
- deps: compression@~1.0.9

lib/response.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,11 @@ res.jsonp = function(obj){
308308
*
309309
* Options:
310310
*
311-
* - `maxAge` defaulting to 0
312-
* - `root` root directory for relative filenames
311+
* - `maxAge` defaulting to 0
312+
* - `root` root directory for relative filenames
313+
* - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them
314+
*
315+
* Other options are passed along to `send`.
313316
*
314317
* Examples:
315318
*
@@ -385,10 +388,7 @@ res.sendfile = function(path, options, fn){
385388
}
386389

387390
// transfer
388-
var file = send(req, path, {
389-
maxAge: options.maxAge || 0,
390-
root: options.root
391-
});
391+
var file = send(req, path, options);
392392
file.on('error', error);
393393
file.on('directory', next);
394394
file.on('stream', stream);

test/fixtures/.name

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tobi

test/res.sendfile.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ describe('res', function(){
106106
})
107107

108108
describe('.sendfile(path)', function(){
109+
it('should not serve dotfiles', function(done){
110+
var app = express();
111+
112+
app.use(function(req, res){
113+
res.sendfile('test/fixtures/.name');
114+
});
115+
116+
request(app)
117+
.get('/')
118+
.expect(404, done);
119+
})
120+
121+
it('should accept dotfiles option', function(done){
122+
var app = express();
123+
124+
app.use(function(req, res){
125+
res.sendfile('test/fixtures/.name', { dotfiles: 'allow' });
126+
});
127+
128+
request(app)
129+
.get('/')
130+
.expect(200, 'tobi', done);
131+
})
132+
109133
describe('with an absolute path', function(){
110134
it('should transfer the file', function(done){
111135
var app = express();

0 commit comments

Comments
 (0)