Skip to content

fix(state): do not check content type if no input #6794

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

Conversation

alexndlm
Copy link
Contributor

Q A
Branch? 3.4
Tickets
License MIT
Doc PR

Problem appears after #6102

@alexndlm alexndlm changed the base branch from main to 3.4 November 14, 2024 12:53
@alexndlm alexndlm force-pushed the feature/skip-content-negotiation-for-application-x-www-form-urlencoded-and-no-input branch from 46e9bcb to ff39f5b Compare November 14, 2024 13:18
@alexndlm alexndlm changed the title fix(state): allow application/x-www-form-urlencoded content-type when no input fix(state): do not check content type if no input Nov 14, 2024

if (!$request->isMethodSafe() && 'DELETE' !== $request->getMethod()) {
throw new UnsupportedMediaTypeHttpException(\sprintf('The content-type "%s" is not supported. Supported MIME types are "%s".', $contentType, implode('", "', $supportedMimeTypes)));
}

Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to not set input formats in
https://github.com/api-platform/core/blob/3.4/src/Metadata/Resource/Factory/FormatsResourceMetadataCollectionFactory.php#L79

when deserialize is false? Or do you think that the problem should be handled here? In that case can you check https://gist.github.com/soyuka/beac00bc527d2ea6e703ed27dd67532c/revisions (first is with the suggested patch, the second if we can move the handling of the formats to FormatsResourceMetadataCollectionFactory instead as there's no point having input formats if we don't deserialize imo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to check if the operation has input in the ContentNegotiationProvider even if we do not set the input format in FormatsResourceMetadataCollectionFactory.

So, to avoid overcomplicating the code and possibly not introducing some bugs or BC, I prefer not to change the FormatsResourceMetadataCollectionFactory logic.

And I apply your suggestion.

@alexndlm alexndlm marked this pull request as draft November 14, 2024 15:20
@alexndlm alexndlm marked this pull request as ready for review November 14, 2024 15:51
@alexndlm alexndlm requested a review from soyuka November 14, 2024 15:51
@soyuka soyuka merged commit bec147b into api-platform:3.4 Nov 15, 2024
77 of 78 checks passed
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.

2 participants