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
415 error on routes that does not exist with body multipart/form-data #381
Comments
Good spot! We should basically skip all the incoming body if it's a 404 request. This can be done by adding a few if checks in fastify-multipart using the Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
Sorry about the delay, the email notification did not work. will look at it as soon as possible |
Hey @mcollina I don't think that this is the issue with fastify-multipart, this is issue with Should this be done in fastify itself ? This is because unregistered content type can cause 415 so checking if the route exist before checking the content type is registered is a good idea As you could see at that 404 routes are handled by the default handler in so adding |
I have made a pull request, fastify/fastify#4286 |
Good spot, thanks! |
- check if the route is 404 only if the content-parser is undefined by this we can avoid breaking changes. - this also passes previous tests this resolves issue - fastify/fastify-multipart#381
* check if route exist before checking content type * added test for route check before content type * pass tests - check if the route is 404 only if the content-parser is undefined by this we can avoid breaking changes. - this also passes previous tests this resolves issue - fastify/fastify-multipart#381 * Update lib/contentTypeParser.js Noted, thanks for the review Co-authored-by: Manuel Spigolon <behemoth89@gmail.com> * pass tests from wrong return Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
Prerequisites
Fastify version
4.0.0
Plugin version
7.1.0
Node.js version
v16.16.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
12.5 (21G72)
Description
Fastify handles 404 for us, but when used with fastify multipart. it creates an 415 error instead of 404 for routes that does not exist. To demonstrate this I have created a project with fastify cli and tracked the steps to reproduce in each commits Link to repo.
I have tested a bunch of request with different method
As you could see I'm getting 404 for a route that does not exist when using no body in POST request method
Now lets change the body type to
multipart/form-data
and send the requestThis issue is the cause of issue #379 and created new issue as #379 (comment)
Steps to Reproduce
@fastify/multipart
pluginmultipart/form-data
as body to any route that does not exist. In our case I used/notfound
route.Expected Behavior
POST
,PUT
,PATCH
,DELETE
route that does not exist.The text was updated successfully, but these errors were encountered: