Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,11 @@ res.sendFile = function sendFile(path, options, callback) {
// create file stream
var pathname = encodeURI(path);

// wire application etag option to send
opts.etag = this.app.enabled('etag');
// wire application etag option to send, unless the caller
// passed an explicit etag option for this response
if (opts.etag === undefined) {
opts.etag = this.app.enabled('etag');
}
var file = send(req, pathname, opts);

// transfer
Expand Down
13 changes: 13 additions & 0 deletions test/res.download.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ describe('res', function(){
.expect(200, '<p>{{user.name}}</p>', done)
})

it('should disable the ETag when the etag option is false', function (done) {
var app = express()

app.get('/', function (req, res) {
res.download('test/fixtures/user.html', { etag: false })
})

request(app)
.get('/')
.expect(utils.shouldNotHaveHeader('ETag'))
.expect(200, '<p>{{user.name}}</p>', done)
})

it('should respond with requested byte range', function (done) {
var app = express()

Expand Down
18 changes: 18 additions & 0 deletions test/res.sendFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ describe('res', function(){
}
});

it('should disable the ETag function when the etag option is false', function (done) {
var app = createApp(path.resolve(fixtures, 'name.txt'), { etag: false });

request(app)
.get('/')
.expect(utils.shouldNotHaveHeader('ETag'))
.expect(200, 'tobi', done);
});

it('should enable the ETag function when the etag option is true', function (done) {
var app = createApp(path.resolve(fixtures, 'name.txt'), { etag: true }).disable('etag');

request(app)
.get('/')
.expect(utils.shouldHaveHeader('ETag'))
.expect(200, 'tobi', done);
});

it('should 404 for directory', function (done) {
var app = createApp(path.resolve(fixtures, 'blog'));

Expand Down