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

Add an HTTP client which uses fetch. #1236

Merged
merged 5 commits into from
Sep 8, 2021
Merged

Add an HTTP client which uses fetch. #1236

merged 5 commits into from
Sep 8, 2021

Conversation

dcr-stripe
Copy link
Contributor

@dcr-stripe dcr-stripe commented Sep 8, 2021

Notify

r? @richardm-stripe

Summary

Adds an HttpClient implementation that uses the Fetch API.

This paves the way for unblocking #997.

Test plan

The common tests are shared between NodeHttpClient and FetchHttpClient to make sure both meet the requirements for the interface (modulo some streaming/raw response tests, as this is implementation-dependant). In order to test fetch as part of our Node testing environment, the node-fetch polyfill is used.

@dcr-stripe dcr-stripe changed the title [WIP] Add an HTTP client which uses fetch. Add an HTTP client which uses fetch. Sep 8, 2021
this._fetchFn = fetchFn;
}

/* eslint-disable class-methods-use-this */
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we globally disable this rule? We seem to violate it all the time and I don't really agree with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Agreed.

Co-authored-by: Richard Marmorstein <[email protected]>
const headersObj = {};

for (const entry of headers) {
headersObj[entry[0]] = entry[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT of throwing an exception here if entry is not an array with two entries?
I think maybe it's worth being more defensive here because fetchFn is injected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Done.

});
});

it('toJSON accumulates all data chunks in utf-8 encoding', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

Copy link
Contributor

@richardm-stripe richardm-stripe left a comment

Choose a reason for hiding this comment

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

LGTM! Left a few minor suggestions - I am so excited for this

@dcr-stripe
Copy link
Contributor Author

Added fixes. PTAL @richardm-stripe ? Thanks for the feedback!

@dcr-stripe dcr-stripe merged commit b4298e6 into master Sep 8, 2021
@dcr-stripe dcr-stripe deleted the dcr-fetch-client branch September 8, 2021 21:14
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.

2 participants