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

fix: set no-op proxy config to get Vite HTTPS working #12907

Merged
merged 10 commits into from
Nov 5, 2024
Merged

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Oct 29, 2024

closes #11365

cc: @Conduitry @benmccann

This PR gets the Vite HTTPS working again by filtering out two types of keys from the incoming request headers object before we pass it to a new Request object. Doing so prevents the two errors we currently encounter as shown below.

  1. When there's a symbol key in the request headers:
TypeError: Request constructor: init.headers is a symbol, which cannot be converted to a DOMString.
    at webidl.errors.exception (node:internal/deps/undici/undici:3384:14)
    at webidl.converters.DOMString (node:internal/deps/undici/undici:3650:29)
    at webidl.converters.ByteString (node:internal/deps/undici/undici:3658:35)
    at Object.record<ByteString, ByteString> (node:internal/deps/undici/undici:3567:30)
    at webidl.converters.HeadersInit (node:internal/deps/undici/undici:8715:67)
    at Object.RequestInit (node:internal/deps/undici/undici:3624:21)
    at new Request (node:internal/deps/undici/undici:9267:34)
    at getRequest (file:///home/chewteeming/my-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/node/index.js:122:9)
    at file:///home/chewteeming/my-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:497:27
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  1. When there's HTTP/2 pseudo-headers in the request headers (partially reimplements https://github.com/sveltejs/kit/pull/3572/files):
TypeError: Headers.append: ":method" is an invalid header name.
    at webidl.errors.exception (node:internal/deps/undici/undici:3384:14)
    at webidl.errors.invalidArgument (node:internal/deps/undici/undici:3395:28)
    at appendHeader (node:internal/deps/undici/undici:8339:29)
    at fill (node:internal/deps/undici/undici:8325:11)
    at new Request (node:internal/deps/undici/undici:9490:13)
    at getRequest (file:///home/chewteeming/my-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/node/index.js:118:9)
    at file:///home/chewteeming/my-app/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:497:27

Open to suggestions for a better way to do this.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Oct 29, 2024

🦋 Changeset detected

Latest commit: b604ea4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@eltigerchino eltigerchino changed the title fix: strip HTTP/2 pseudo-headers and symbol keys from requests fix: strip HTTP/2 pseudo-headers and symbol keys from headers Oct 29, 2024
Copy link
Member

@Conduitry Conduitry left a comment

Choose a reason for hiding this comment

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

Since Vite is involved, this is a dev-only issue, right?

The issue we ran into before IIRC is that node-fetch didn't like these headers. That became unnecessary when we switched to Undici.

The function you're modifying in this PR is the main function to generate the Request object in production for various adapters for Node-based systems. This won't immediately make more work in production for apps using them (since the released version of the adapters bundle this code), but eventually it will.

Without looking much at what would be involved with this, my sense is that we should focus on the dev-time code, which would mean adjusting how getRequest is called at

const request = await getRequest({
rather than adjusting the getRequest implementation.

We may then also need to do something for preview-time. But we shouldn't be doing this extra work to normalize requests in prod builds if it's not necessary.

@eltigerchino eltigerchino changed the title fix: strip HTTP/2 pseudo-headers and symbol keys from headers fix: set no-op proxy config to get Vite HTTPS working Oct 29, 2024
@eltigerchino
Copy link
Member Author

eltigerchino commented Oct 29, 2024

Turns out the better alternative was to set the no-op proxy config as implemented previously and is the current workaround. This also fixes another issue with the request URL being set incorrectly that the previous implementation had.

I'm not sure if the config overriding is in the right place, but it doesn't seem to work if done too late such as immediately before configuring the dev and preview server.

@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-kit-12907-svelte.vercel.app/

this is an automated message

@benmccann benmccann merged commit c80b1d8 into main Nov 5, 2024
11 checks passed
@benmccann benmccann deleted the fix-vite-https branch November 5, 2024 00:45
@github-actions github-actions bot mentioned this pull request Nov 5, 2024
@benmccann
Copy link
Member

Awesome to close such a frequently encountered issue! Thanks!!

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.

undici's new Request is incompatible with HTTP/2 requests
4 participants