-
Notifications
You must be signed in to change notification settings - Fork 753
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
Conversation
445ec51
to
8061bdf
Compare
8061bdf
to
01b9ff2
Compare
lib/net/FetchHttpClient.js
Outdated
this._fetchFn = fetchFn; | ||
} | ||
|
||
/* eslint-disable class-methods-use-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.
Shall we globally disable this rule? We seem to violate it all the time and I don't really agree with it.
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.
Done. Agreed.
Co-authored-by: Richard Marmorstein <[email protected]>
const headersObj = {}; | ||
|
||
for (const entry of headers) { | ||
headersObj[entry[0]] = entry[1]; |
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.
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
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.
Good call! Done.
}); | ||
}); | ||
|
||
it('toJSON accumulates all data chunks in utf-8 encoding', async () => { |
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.
nice
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.
LGTM! Left a few minor suggestions - I am so excited for this
Added fixes. PTAL @richardm-stripe ? Thanks for the feedback! |
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.