Skip to content

Commit 85cc7f5

Browse files
juanarbolwesleytodd
authored andcommitted
feat: add support for ETag option in res.sendFile
This patch introduces the ability to control the ETag generation through the `res.sendFile` function. Specifically, the ETag option is wired to the application's configuration, allowing it to be enabled or disabled based on the app's settings. Fixes: #2294 Signed-off-by: Juan José Arboleda <[email protected]>
1 parent d2de128 commit 85cc7f5

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ unreleased
1010
* refactor: prefix built-in node module imports
1111
* Remove unused `depd` dependency
1212
* Add support for `Uint8Array` in `res.send`
13+
* Add support for ETag option in res.sendFile
1314
* deps: debug@^4.4.0
1415
* deps: body-parser@^2.1.0
1516
* deps: router@^2.1.0

lib/response.js

+3
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ res.sendFile = function sendFile(path, options, callback) {
389389

390390
// create file stream
391391
var pathname = encodeURI(path);
392+
393+
// wire application etag option to send
394+
opts.etag = this.app.enabled('etag');
392395
var file = send(req, pathname, opts);
393396

394397
// transfer

test/res.sendFile.js

+13
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ describe('res', function(){
7878
});
7979
});
8080

81+
it('should disable the ETag function if requested', function (done) {
82+
var app = createApp(path.resolve(fixtures, 'name.txt')).disable('etag');
83+
84+
request(app)
85+
.get('/')
86+
.expect(handleHeaders)
87+
.expect(200, done);
88+
89+
function handleHeaders (res) {
90+
assert(res.headers.etag === undefined);
91+
}
92+
});
93+
8194
it('should 404 for directory', function (done) {
8295
var app = createApp(path.resolve(fixtures, 'blog'));
8396

0 commit comments

Comments
 (0)