withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
45.85k stars 2.41k forks source link

fix: support HTTP/2 in `astro dev` #11284

Closed ascorbic closed 3 months ago

ascorbic commented 3 months ago

Changes

The Vite dev server suppports HTTP/2 when the server.https option is set. However this doesn't work in astro dev by default, because we set the vite.server.proxy option (to an empty object). If a user manually enables it by unsetting the proxy option, we generate a malformed Astro.request.url and SSR pages break because we try to set invalid headers.

This PR removes the default proxy config so it is possible to enable HTTP/2 by setting the vite.server.https options. It handles URL correctly now, by chedking the :authority pseudo-header as well as host, and ensures that we don't attempt to create invalid headers when we copy the headers object.

Fixes #10238

Testing

It adds a test fixture based on the repro in #10238 (thanks @alexvuka1). In order to do this, I also added support for TLS and HTTP/2 in our test utils. If the fixture's Astro config enables https, the test utils configure fetch to trust self-signed certs and enable HTTP/2 in our tests.

Docs

I don't think this needs to be documented

changeset-bot[bot] commented 3 months ago

🦋 Changeset detected

Latest commit: 1be0a1f263c63b158b175b071b47062f198a06d7

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

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

ascorbic commented 3 months ago

@ematipico thanks for the review. I've added comments answering both of your questions