Skip to content

Commit f7b47d0

Browse files
committed
response: 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 a46cfdc commit f7b47d0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/response.js

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

392392
// create file stream
393393
var pathname = encodeURI(path);
394+
395+
// wire application etag option to send
396+
opts.etag = this.app.enabled('etag');
394397
var file = send(req, pathname, opts);
395398

396399
// transfer

test/res.sendFile.js

+13
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ describe('res', function(){
8282
});
8383
});
8484

85+
it('should disable the ETag function if requested', function (done) {
86+
var app = createApp(path.resolve(fixtures, 'name.txt')).disable('etag');
87+
88+
request(app)
89+
.get('/')
90+
.expect(handleHeaders)
91+
.expect(200, done);
92+
93+
function handleHeaders (res) {
94+
assert(res.headers.etag === undefined);
95+
}
96+
});
97+
8598
it('should 404 for directory', function (done) {
8699
var app = createApp(path.resolve(fixtures, 'blog'));
87100

0 commit comments

Comments
 (0)