Skip to content
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

read content-type from response #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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