Skip to content
Closed
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
4 changes: 2 additions & 2 deletions lib/node-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Server.prototype.serve = function (req, res, callback) {
}

process.nextTick(function () {
that.servePath(pathname, 200, {}, req, res, finish).on('success', function (result) {
that.servePath(pathname, 200, res._headers, req, res, finish).on('success', function (result) {
promise.emit('success', result);
}).on('error', function (err) {
promise.emit('error');
Expand Down Expand Up @@ -344,7 +344,7 @@ Server.prototype.respondNoGzip = function (pathname, status, contentType, _heade
};

Server.prototype.respond = function (pathname, status, _headers, files, stat, req, res, finish) {
var contentType = _headers['Content-Type'] ||
var contentType = res.getHeader('Content-Type') ||
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also be checking _headers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right.. _headers could contain 'Content-Type' if respondGzip or respondNoGzip was called externally. But comparing _headers to res.getHeader here would cause unexpected behavior when someone tries to set headers via whichever method takes lower precedence.

Would it be better to revert line 347 to current master, but ensure internal calls to respond populate the _headers param from res._headers? There's only two at 59, and 78.

Totally understand if you want to kill this PR and look at a cleaner way to add this functionality to the API, I was just playing around with it.

mime.lookup(files[0]) ||
'application/octet-stream';

Expand Down