Prerequisites
Fastify version
5.0.0
Plugin version
No response
Node.js version
20.17.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11
Description
Spotted whilst trying to upgrade one of my projects from Fastify v4.28.1 to v5.0.0, addContentTypeParser is no longer case-sensitive and will only parse requests if the content-type is in lower-case.
For example, with v4.28.1 addContentTypeParser('application/vnd.ms-word.document.macroEnabled.12', ...) would parse application/vnd.ms-word.document.macroEnabled.12 but not application/vnd.ms-word.document.macroenabled.12, as expected.
With v5.0.0, application/vnd.ms-word.document.macroEnabled.12 is no longer parsed and throws a 415 error, whilst application/vnd.ms-word.document.macroenabled.12 is parsed.
This isn't ideal when there are mime-types that generally have uppercase values in them, such as Microsoft Office documents.
This was not documented as a change in the v5 migration guide, so I assume it is unintended.
Link to code that reproduces the bug
https://github.com/Fdawgs/fastify-content-type-parser-bug
Expected Behavior
With Fastify v4.x addContentTypeParser was case-sensitive, and in v5.0.0 it is lowercase only.
However, both implementations are wrong and it should be case-insensitive as per RFC 2616. and RFC 6838.
Prerequisites
Fastify version
5.0.0
Plugin version
No response
Node.js version
20.17.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11
Description
Spotted whilst trying to upgrade one of my projects from Fastify v4.28.1 to v5.0.0,
addContentTypeParseris no longer case-sensitive and will only parse requests if the content-type is in lower-case.For example, with v4.28.1
addContentTypeParser('application/vnd.ms-word.document.macroEnabled.12', ...)would parseapplication/vnd.ms-word.document.macroEnabled.12but notapplication/vnd.ms-word.document.macroenabled.12, as expected.With v5.0.0,
application/vnd.ms-word.document.macroEnabled.12is no longer parsed and throws a 415 error, whilstapplication/vnd.ms-word.document.macroenabled.12is parsed.This isn't ideal when there are mime-types that generally have uppercase values in them, such as Microsoft Office documents.
This was not documented as a change in the v5 migration guide, so I assume it is unintended.
Link to code that reproduces the bug
https://github.com/Fdawgs/fastify-content-type-parser-bug
Expected Behavior
With Fastify v4.x
addContentTypeParserwas case-sensitive, and in v5.0.0 it is lowercase only.However, both implementations are wrong and it should be case-insensitive as per RFC 2616. and RFC 6838.