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 transitions with non-recommended headers #9464

Merged
merged 5 commits into from
Dec 19, 2023

Conversation

Fryuni
Copy link
Member

@Fryuni Fryuni commented Dec 18, 2023

Changes

The syntax of the Content-Type header specified by the HTTP Semantics RFC is as follows:

Content-Type = media-type

OWS = *( SP / HTAB )

media-type = type "/" subtype parameters

subtype = token
type = token

parameter = parameter-name "=" parameter-value
parameter-name = token
parameter-value = ( token / quoted-string )
parameters = *( OWS ";" OWS [ parameter ] )

tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
 "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
token = 1*tchar

The ; that marks the start of the parameters may, even though not recommended, be preceded by any number of white spaces. The previous implementation of the fetchHTML function would not accept a header in that form and do full page reload.

This PR takes that into account and replaces the media type extraction from the header with an implementation that works for any spec-compliant server, even without using recommended practices.

Testing

A new integration test was added for a page replying with the following header:

Content-Type: text/html ; charset=utf-8

Docs

I don't think this needs any docs change

Copy link

changeset-bot bot commented Dec 18, 2023

🦋 Changeset detected

Latest commit: 83134ec

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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Dec 18, 2023
@Fryuni Fryuni changed the title Fix transitions with weird server Fix transitions with non-recommended headers Dec 18, 2023
packages/astro/src/transitions/router.ts Show resolved Hide resolved
.changeset/khaki-ducks-give.md Outdated Show resolved Hide resolved
Copy link
Member

@martrapp martrapp left a comment

Choose a reason for hiding this comment

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

I read about it in your article ;-)
Many thanks for this improvement!

@martrapp martrapp merged commit faf6c7e into withastro:main Dec 19, 2023
13 checks passed
@Fryuni Fryuni deleted the fix/transitions-with-weird-server branch December 19, 2023 19:59
@astrobot-houston astrobot-houston mentioned this pull request Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants