Skip to content
Myr

feat: add support for ETag option in res.sendFile (#6073)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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: https://github.com/expressjs/express/issues/2294

authored by Juan José · committed by GitHub · parent d2de128 · Browse files · 3 files+17 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>

Diff stats

3 files+17 added−0 removed

  • tests:+13 added−0 removed
  • other:+4 added−0 removed

3 files+17 added−0 removed

modified:lib/response.js+3 added
387 unmodified lines
388 }389390 // create file stream391 var pathname = encodeURI(path);392393 // wire application etag option to send394 opts.etag = this.app.enabled('etag');395 var file = send(req, pathname, opts);396397 // transfer398 sendfile(res, file, opts, function (err) {
630 unmodified lines
modified:test/res.sendFile.js+13 added
76 unmodified lines
77 .expect(304, done);78 });79 });8081 it('should disable the ETag function if requested', function (done) {82 var app = createApp(path.resolve(fixtures, 'name.txt')).disable('etag');8384 request(app)85 .get('/')86 .expect(handleHeaders)87 .expect(200, done);8889 function handleHeaders (res) {90 assert(res.headers.etag === undefined);91 }92 });9394 it('should 404 for directory', function (done) {95 var app = createApp(path.resolve(fixtures, 'blog'));9697 request(app)
815 unmodified lines
modified:History.md+1 added
8 unmodified lines
9* Replace `methods` dependency with standard library10* refactor: prefix built-in node module imports11* Remove unused `depd` dependency12* Add support for `Uint8Array` in `res.send`13* Add support for ETag option in res.sendFile14* deps: debug@^4.4.015* deps: body-parser@^2.1.016* deps: router@^2.1.017* deps: nyc@^17.1.0
3843 unmodified lines