Skip to content

Use Node-Fetch instead of Request for TS client #19708

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

Merged
merged 4 commits into from
Mar 14, 2020
Merged

Conversation

BrennanConroy
Copy link
Member

The request module has been deprecated, so we're taking this opportunity to share our fetch code with the browser and Node by using a fetch polyfill on Node.

Fixes #19420

@BrennanConroy BrennanConroy added the area-signalr Includes: SignalR clients and servers label Mar 9, 2020
// fetch-cookie will wrap a fetch implementation with a default CookieJar or a provided one
fetchType = requireFunc("fetch-cookie")(fetchType, jar);

// Node needs EventListener methods on AbortController which our custom polyfill doesn't provide
Copy link
Contributor

Choose a reason for hiding this comment

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

How complex would it be to add it to our polyfill?

Copy link
Member Author

@BrennanConroy BrennanConroy Mar 9, 2020

Choose a reason for hiding this comment

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

Difficult because I have no idea how to work with the EventListener API.

I gave it a quick try and failed miserably.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can't just use https://nodejs.org/api/events.html because our polyfill still has to work on the browser.

@@ -97,6 +124,15 @@ export class FetchHttpClient extends HttpClient {
payload,
);
}

public getCookieString(url: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this for?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the way we apply cookies to WebSockets and SSE

Copy link
Contributor

Choose a reason for hiding this comment

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

So where do we call it? I don't see it in the diff anywhere and it looks new.

Copy link
Member Author

Choose a reason for hiding this comment

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

It isn't new. It just has a default implementation and since the FetchHttpClient wasn't used in Node before it wasn't needed. But now it is.

One usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah riiiiight. Ok, thanks for clearing that up. Just saw a new public API and was confused. There's a good reason C# has the override keyword ;P.

@BrennanConroy BrennanConroy added this to the 5.0.0-preview3 milestone Mar 13, 2020
@BrennanConroy BrennanConroy merged commit 37c2a88 into master Mar 14, 2020
@BrennanConroy BrennanConroy deleted the brecon/node-fetch branch March 14, 2020 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SignalR client depends on deprecated npm package "request"
3 participants