Skip to content

feat: implement net.fetch - #36733

Merged
nornagon merged 54 commits into
mainfrom
net-fetch
Feb 20, 2023
Merged

feat: implement net.fetch#36733
nornagon merged 54 commits into
mainfrom
net-fetch

Conversation

@nornagon

@nornagon nornagon commented Dec 22, 2022

Copy link
Copy Markdown
Contributor

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 removed the new-pr 🌱 PR opened recently label Dec 29, 2022
@nornagon

Copy link
Copy Markdown
Contributor 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 recently label Jan 26, 2023
Comment thread docs/api/net.md Outdated
@nornagon

Copy link
Copy Markdown
Contributor Author

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

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

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

release-clerk Bot commented Feb 20, 2023

Copy link
Copy Markdown

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.

6 participants