Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

Handle multiply defined headers #1

Merged
merged 12 commits into from
Oct 8, 2015
Merged

Conversation

mbland
Copy link
Contributor

@mbland mbland commented Oct 2, 2015

Maintains parity with 18F/hmacauth#1. We should wait for that PR to go in before reviewing/submitting this one (unless you want to check it out for style ahead of time).

cc: @dhcole @jeremiak

@mbland mbland force-pushed the handle-multiply-defined-headers branch from 3f4af68 to 4f0aeba Compare October 3, 2015 22:54
@mbland
Copy link
Contributor Author

mbland commented Oct 5, 2015

OK, 18F/hmacauth#1 is in. I've kept this PR in tight sync with that one. Either of y'all mind taking a peek sometime?

@mbland
Copy link
Contributor Author

mbland commented Oct 6, 2015

cc: @ccostino

return headers.map(function(header) { return req.get(header) || ''; });
return headers.map(function(header) {
var value = req.headers[header];
if (typeof value === Array) { value = value.join(','); }
Copy link

Choose a reason for hiding this comment

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

If value is an array, typeof value would return 'object' (a string). How about testing for what you intend to use, in this case:

if (typeof value !== 'string' && typeof value.join === 'function') { 
  value = value.join(','); 
}

Copy link

Choose a reason for hiding this comment

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

Actually, that would miss undefined values, and since this is specifically for Node and we don't need to worry about older browsers, how about using if (Array.isArray(value)) { ... }?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, it passed my multiply-defined header test, but I agree Array.isArray() is the way to roll. Done.

Copy link

Choose a reason for hiding this comment

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

I think the test passed because typeof value === Array fails, so the
join() call is skipped, but later the value array is being coerced to a
string and ['foo', 'bar'].toString() => "foo,bar" — the same output as
the join method.

@dhcole
Copy link

dhcole commented Oct 8, 2015

Looks great! I'd say 🚢 away

@mbland
Copy link
Contributor Author

mbland commented Oct 8, 2015

Thanks, @dhcole!

mbland added a commit that referenced this pull request Oct 8, 2015
@mbland mbland merged commit f81fa44 into master Oct 8, 2015
@mbland mbland deleted the handle-multiply-defined-headers branch October 8, 2015 09:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants