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
17 changes: 16 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,22 @@ defineGetter(req, 'fresh', function(){

// 2xx or 304 as per rfc2616 14.26
if ((s >= 200 && s < 300) || 304 === s) {
return fresh(this.headers, (this.res._headers || {}));
var resHeaders = this.res._headers || {};

// Support changes in node with how response headers are stored
var headerNames = this.res._headerNames || {};
var keys = Object.keys(resHeaders);
if (keys.length > 0 && headerNames[keys[0]] === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a whole lot of Node.js http mock libraries out there (https://github.com/howardabrams/node-mocks-http comes to mind) and they have never mocked the _headerNames object. I think this would cause the usage of those modules to change the behavior (probably break) people's tests for Express projects that use them since this code would detect those mocks as the new style of headers and then copy all the header values as undefined, right?

var oldResHeaders = {};
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
// resHeaders[key] === [originalCasedKey, value]
oldResHeaders[key] = resHeaders[key][1];
}
resHeaders = oldResHeaders;
}

return fresh(this.headers, resHeaders);
}

return false;
Expand Down