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
Merged
Changes from 2 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
9 changes: 6 additions & 3 deletions packages/apollo-engine-reporting/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ export class EngineReportingExtension<TContext = any>
for (const [key, value] of o.request.headers) {
if (
this.options.privateHeaders &&
typeof this.options.privateHeaders === 'object' &&
Array.isArray(this.options.privateHeaders) &&
// We assume that most users only have a few private headers, or will
// just set privateHeaders to true; we can change this linear-time
// operation if it causes real performance issues.
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.

})
) {
continue;
}
Expand Down Expand Up @@ -164,7 +167,7 @@ export class EngineReportingExtension<TContext = any>
Object.keys(o.variables).forEach(name => {
if (
this.options.privateVariables &&
typeof this.options.privateVariables === 'object' &&
Array.isArray(this.options.privateVariables) &&
// We assume that most users will have only a few private variables,
// or will just set privateVariables to true; we can change this
// linear-time operation if it causes real performance issues.
Expand Down