Skip to content

Implement OptionalFromRequest for Form and RawForm #3355

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

avalon1610
Copy link

Motivation

This change enables the use of Form as an optional extractor in certain scenarios.

Solution

This PR implements OptionalFromRequest for Form and RawForm. The behavior is as follows:

  • For GET or HEAD requests, if there are no query parameters, the extractor will return None. Otherwise, it will parse the form data using the original logic.
  • For other HTTP methods, if the Content-Type header is not present, the extractor will return None. Otherwise, it will parse the form data using the original logic.

Additionally, the FromRequest implementation for RawForm does not include a check for the HEAD method. I believe this is a bug, as Form and RawForm should behave consistently. Is this understanding correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant