-
-
Notifications
You must be signed in to change notification settings - Fork 17.4k
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
res.sendFile: inherit etag setting from app #2936
Changes from 1 commit
3bd3121
8251963
4846c91
f45395c
4086446
82408a8
d0acf61
1ad5b2b
b93130b
cb65985
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,6 +358,9 @@ res.sendFile = function sendFile(path, options, callback) { | |
var res = this; | ||
var next = req.next; | ||
var opts = options || {}; | ||
|
||
// settings | ||
var app = this.app; | ||
|
||
if (!path) { | ||
throw new TypeError('path argument is required to res.sendFile'); | ||
|
@@ -368,6 +371,10 @@ res.sendFile = function sendFile(path, options, callback) { | |
done = options; | ||
opts = {}; | ||
} | ||
|
||
if (app.settings.etag == false) { | ||
opts.etag = app.settings.etag; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect that if the user explicitly set the |
||
} | ||
|
||
if (!opts.root && !pathIsAbsolute(path)) { | ||
throw new TypeError('path must be absolute or specify root to res.sendFile'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,26 @@ describe('res', function(){ | |
.expect('Content-Type', 'application/x-bogus') | ||
.end(done); | ||
}) | ||
|
||
it('should set etag according to app settings', function (done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test that checks the behavior when someone sets the etag setting to |
||
var app = express(); | ||
|
||
app.disable('etag'); | ||
app.use(function (req, res) { | ||
res.sendFile(path.resolve(fixtures, 'name.txt')); | ||
}); | ||
|
||
request(app) | ||
.get('/') | ||
.end(function(err, res) { | ||
if (err) { | ||
return done(err); | ||
} | ||
assert.equal('etag' in res.headers, false); | ||
done(); | ||
}); | ||
}) | ||
|
||
|
||
it('should not error if the client aborts', function (done) { | ||
var cb = after(1, done); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use the setting functions to access settings, not direct access to the object. Direct object access was deprecated in 3.0.