-
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
Changes from all commits
8fbfcf0
3d44da5
c6e4980
ba524bb
683a764
e3f36a9
2d0551b
907bed4
df3a1b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,6 +317,9 @@ var _parseConfig = function _parseConfig(options, config) { | |
return; | ||
} | ||
|
||
// Add exception in headers | ||
const freeFormObjectKeys = new Set(['headers']); | ||
|
||
// validates config value is defined, is the correct type, and some additional value sanity checks | ||
var parseValidateAndLoad = function parseValidateAndLoad(key) { | ||
if (!Object.prototype.hasOwnProperty.call(options, key)) { | ||
|
@@ -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 commentThe 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? |
||
} else if (Object.prototype.hasOwnProperty.call(config, key)) { | ||
parseValidateAndLoad(key); | ||
} | ||
} | ||
|
@@ -1520,7 +1525,7 @@ AmplitudeClient.prototype.sendEvents = function sendEvents() { | |
}; | ||
|
||
var scope = this; | ||
new Request(url, data).send(function (status, response) { | ||
new Request(url, data, this.options.headers).send(function (status, response) { | ||
scope._sending = false; | ||
try { | ||
if (status === 200 && response === 'success') { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import language from './language'; | |
* @property {string} [unsentKey=`amplitude_unsent`] - localStorage key that stores unsent events. | ||
* @property {string} [unsentIdentifyKey=`amplitude_unsent_identify`] - localStorage key that stores unsent identifies. | ||
* @property {number} [uploadBatchSize=`100`] - The maximum number of events to send to the server per request. | ||
* @property {Object} [headers=`{ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }`] - Headers attached to an event(s) upload network request. Custom header properties are merged with this object. | ||
*/ | ||
export default { | ||
apiEndpoint: 'api.amplitude.com', | ||
|
@@ -89,4 +90,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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, don't forget to put a comment for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added docs explaining this |
||
}; |
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
?