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

Compare Engine reporting's privateHeaders case-insensitively, as documented. #2276

Merged
merged 3 commits into from Feb 7, 2019

Conversation

abernix
Copy link
Member

@abernix abernix commented Feb 6, 2019

The documentation for privateHeaders[0] suggests that it is case-insensitive. While that statement is true, and the incoming header is lower-cased before checking it against the privateHeaders configuration, it assumed that the headers in the privateHeaders object were specified in lower-case.

This changes the comparison to lower-case both sides prior to determining equality.

Fixes: #2273

…cumented.

The documentation for `privateHeaders`[[0]] suggests that it is
case-insensitive.  While that statement is true, and the incoming header is
lower-cased before checking it against the `privateHeaders` configuration,
it assumed that the headers in the `privateHeaders` object were specified in
lower-case.

This changes the comparison to lower-case both sides prior to determining
equality.

[0]: https://github.com/apollographql/apollo-server/blob/abb8dc58/packages/apollo-engine-reporting/src/agent.ts#L67-L70

Fixes: #2273
@abernix abernix force-pushed the abernix/allow-any-case-for-privateHeaders branch from 927fe47 to 5ee9845 Compare February 6, 2019 10:50
this.options.privateHeaders.includes(key.toLowerCase())
this.options.privateHeaders.some(privateHeader => {
// Headers are case-insensitive, and should be compared as such.
return privateHeader.toLowerCase() === key.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sense to me! We can do things to improve performance of course, like not calling key.toLowerCase() for every privateHeader, making sure to store private headers in lower case, or even using something like a Set for easy lookup (which I think is what that comment also alludes to), but none of that is likely to matter in practice, and this makes the intention immediately clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree. I tried to avoid doing any micro-optimization right now since we'll (probably soon-ish?) want to introduce the ability to define this as a function and its less clear how beneficial it would be to build that out given that direction (and such an implementation could benefit from its own optimizations). Unless there are a large number of privateHeaders defined here, I don't think this relatively simple string manipulation would benefit, noticeably, right now.

@abernix abernix merged commit ce4e504 into master Feb 7, 2019
@abernix abernix deleted the abernix/allow-any-case-for-privateHeaders branch February 7, 2019 10:38
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
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.

None yet

3 participants