Skip to content

addContentTypeParser() no longer case-sensitive #5740

@Fdawgs

Description

@Fdawgs

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions