Skip to content

response: add support for ETag option in res.sendFile #6073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
Merged
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
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ unreleased
* refactor: prefix built-in node module imports
* Remove unused `depd` dependency
* Add support for `Uint8Array` in `res.send`
* Add support for ETag option in res.sendFile
* deps: debug@^4.4.0
* deps: body-parser@^2.1.0
* deps: router@^2.1.0
3 changes: 3 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
@@ -389,6 +389,9 @@ 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');
var file = send(req, pathname, opts);

// transfer
13 changes: 13 additions & 0 deletions test/res.sendFile.js
Original file line number Diff line number Diff line change
@@ -78,6 +78,19 @@ describe('res', function(){
});
});

it('should disable the ETag function if requested', function (done) {
var app = createApp(path.resolve(fixtures, 'name.txt')).disable('etag');

request(app)
.get('/')
.expect(handleHeaders)
.expect(200, done);

function handleHeaders (res) {
assert(res.headers.etag === undefined);
}
});

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