Skip to content

Conversation

@leviwheatcroft
Copy link

currently I don't think there's any way to set headers on a per request basis.. this patch allows headers to be set prior to calling nodeStatic.serve.

In addition, currently Content-Type would never be set before being read at line 347, by using res.getHeader you allow this header to be explicitly set on this response outside this module.


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants