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: add Content-Type header for POST requests made by enhance #12198

Conversation

allozaur
Copy link
Contributor

@allozaur allozaur commented May 8, 2024

This PR introduces passing the <form>'s enctype value or formSubmitter's formenctype value to Content-Type header for POST request made when executing the use:enhance function and a default1 value of application/x-www-form-urlencoded when the <form> element doesn't have the enctype attribute specified or has an invalid value2 provided.

When the enctype or formenctype is set to multipart/form then we don't provide the Content-Type header for fetch request

Close #1936


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:kit 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.

Footnotes

  1. https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/enctype

  2. https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-attributes

Copy link

changeset-bot bot commented May 8, 2024

🦋 Changeset detected

Latest commit: a0d82a8

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

@allozaur
Copy link
Contributor Author

allozaur commented May 8, 2024

This is my first PR here so I'm sorry for any imperfections it might have 😅

I am not sure i got the changelog done right... besides that i think that the code is ready to be reviewed by a team member.

@allozaur allozaur marked this pull request as ready for review May 8, 2024 14:33
@eltigerchino
Copy link
Member

Might want to also check why the ubuntu chromium tests are failing.

@eltigerchino eltigerchino added the forms Stuff relating to forms and form actions label May 10, 2024
@eltigerchino eltigerchino changed the title Add Content-Type header for POST requests made by enhance fix: add Content-Type header for POST requests made by enhance May 16, 2024
@allozaur allozaur force-pushed the 1936-respect-form-enctype-in-progressive-enhancement branch from 298384b to b62aa34 Compare May 27, 2024 13:21
… set `application/x-www-form-urlencoded` as a default `Content-Type` for `POST` requests made by `enhance`
@allozaur allozaur force-pushed the 1936-respect-form-enctype-in-progressive-enhancement branch from b62aa34 to e48e31e Compare May 27, 2024 13:24
@allozaur allozaur requested a review from eltigerchino May 27, 2024 13:40
@allozaur
Copy link
Contributor Author

@eltigerchino i've fixed up the tests for use:enhance and now i've got them all working :) i think that this PR is ready for reviewing and then adding it as a part of the next release ;)

packages/kit/src/runtime/app/forms.js Outdated Show resolved Hide resolved
packages/kit/src/runtime/app/forms.js Outdated Show resolved Hide resolved
packages/kit/src/runtime/app/forms.js Outdated Show resolved Hide resolved
allozaur and others added 2 commits May 28, 2024 11:01
@allozaur allozaur requested a review from eltigerchino June 22, 2024 11:35
@eltigerchino
Copy link
Member

eltigerchino commented Jun 23, 2024

Thank you so much! This should be good to merge once CI passes (might need a few retries for the other flaky tests).

@eltigerchino eltigerchino merged commit 8429847 into sveltejs:main Jun 24, 2024
11 of 12 checks passed
@github-actions github-actions bot mentioned this pull request Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forms Stuff relating to forms and form actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect the form enctype in progressive form enhancement example
2 participants