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

feat: Add HTTP header configurations to options #379

Merged
merged 9 commits into from
Apr 28, 2021
Merged

Conversation

jooohhn
Copy link
Contributor

@jooohhn jooohhn commented Apr 19, 2021

Summary

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: NO

@jooohhn jooohhn requested review from ajhorst and kelvin-lu April 19, 2021 19:05
@@ -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',
},
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added docs explaining this

@ajhorst
Copy link
Contributor

ajhorst commented Apr 19, 2021

Left two small comments, otherwise looks good

Copy link
Contributor

@kelvin-lu kelvin-lu left a 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)?

@jooohhn
Copy link
Contributor Author

jooohhn commented Apr 26, 2021

@kelvin-lu Updated code to account for freeform properties like options.headers

@jooohhn jooohhn merged commit 4aaa26f into main Apr 28, 2021
@jooohhn jooohhn deleted the feat-custom-headers branch April 28, 2021 17:30
github-actions bot pushed a commit that referenced this pull request Apr 28, 2021
# [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']);
Copy link
Contributor

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] };
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom request headers
3 participants