-
Notifications
You must be signed in to change notification settings - Fork 134
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
feat: Add HTTP header configurations to options #379
Conversation
@@ -89,4 +89,7 @@ export default { | |||
unsentKey: 'amplitude_unsent', | |||
unsentIdentifyKey: 'amplitude_unsent_identify', | |||
uploadBatchSize: 100, | |||
headers: { | |||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this option is a nested object, will a user passing in their own headers completely overwrite this (and therefore delete this Content-Type
value)? Or will it keep Content-Type and append new headers from there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, don't forget to put a comment for headers
at the description of all the possible options at the top of this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added docs explaining this
Left two small comments, otherwise looks good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is enough - in our option validation, I feel like _parseConfig
will remove any keys that aren't in the default options (e.g. any one that's not Content-Type
) - could you confirm this + add in the unit test cases a completely new header - perhaps (Authorization
: Bearer NOT_A_REAL_BEARER_TOKEN
)?
@kelvin-lu Updated code to account for freeform properties like |
# [8.2.0](v8.1.0...v8.2.0) (2021-04-28) ### Features * Add HTTP header configurations to options ([#379](#379)) ([4aaa26f](4aaa26f))
@@ -317,6 +317,9 @@ var _parseConfig = function _parseConfig(options, config) { | |||
return; | |||
} | |||
|
|||
// Add exception in headers | |||
const freeFormObjectKeys = new Set(['headers']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - this belongs better in the options.js
?
@@ -342,7 +345,9 @@ var _parseConfig = function _parseConfig(options, config) { | |||
}; | |||
|
|||
for (var key in config) { | |||
if (Object.prototype.hasOwnProperty.call(config, key)) { | |||
if (freeFormObjectKeys.has(key)) { | |||
options[key] = { ...options[key], ...config[key] }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might want to add a TODO to find a better soln here - this bypasses all checks, right?
There are still probably some checks to this - as in, header values can't be functions or nested objects, right?
Summary
headers
tooptions
options.headers
Checklist