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: implement net.fetch #36733

Merged
merged 54 commits into from Feb 20, 2023
Merged

feat: implement net.fetch #36733

merged 54 commits into from Feb 20, 2023

Conversation

nornagon
Copy link
Member

@nornagon nornagon commented Dec 22, 2022

Description of Change

This implements net.fetch(), by analogy to fetch() on the Web and fetch()
in Node, but using Chromium's network stack.

Checklist

Release Notes

Notes: Added net.fetch().

@nornagon nornagon added no-backport semver/minor backwards-compatible functionality labels Dec 22, 2022
@electron-cation electron-cation bot added new-pr 🌱 PR opened in the last 24 hours api-review/requested 🗳 labels Dec 22, 2022
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Dec 29, 2022
@nornagon
Copy link
Member Author

Alrighty, I've been running this implementation against the Web Platform Tests (WPT) via a hacked-up version of undici's test harness, and it's doing pretty good so far:

[fetch]: Completed: 900, failed: 178, success: 722, expected failures: 139, unexpected failures: 39, skipped: 7

the remaining "unexpected failures" are:

  • when we reject a body promise due to an abort signal, it doesn't get rejected until after the next microtask. this is because our body stream rejection goes through a Node.js stream close, which emits on nextTick. This seems like an okay bug to ship with, I think.
  • Response.type is returning 'default' instead of 'basic' in many cases. This isn't fixable without patching undici, since it doesn't allow setting the type of the Response object.
  • Response.url always returns '' (again, we'd have to patch undici to make this work)
  • the test Fetch on 425 response should not be retried for non TLS early data. is failing, but Chrome also fails that test: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/fetch/api/basic/http-response-code.any-expected.txt;l=2;drc=f2d84e666d3463d55d7b6d78f2329941e389ae5a, so I don't think that's our fault. We fail it with a slightly different error message (0 connections created instead of 2 connections created).
  • the 'integrity' feature is not implemented. In Chrome, this happens on the Blink side, not in the network service, so we'd have to reimplement it or borrow undici's implementation somehow.
  • we don't correctly preserve http header case (we downcase all headers; the spec expects to keep the case of the first set header)

In addition, net.fetch doesn't support data: or blob: schemes.

I think none of these are sufficiently bad problems to prevent shipping, so I'm taking this out of draft mode.

@nornagon nornagon marked this pull request as ready for review January 26, 2023 20:33
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 26, 2023
docs/api/net.md Outdated Show resolved Hide resolved
@nornagon
Copy link
Member Author

@nornagon nornagon requested a review from a team as a code owner February 13, 2023 20:37
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

Seems like changes from #37099 are mixed in, a rebase would be good.

@release-clerk
Copy link

release-clerk bot commented Feb 20, 2023

Release Notes Persisted

Added net.fetch().

khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
gecko19 pushed a commit to brightsign/electron that referenced this pull request Feb 28, 2023
gecko19 pushed a commit to brightsign/electron that referenced this pull request Feb 28, 2023
gecko19 pushed a commit to brightsign/electron that referenced this pull request Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants