Skip to content

Allow custom parsers to recover content types - #6918

Closed
bcomnes wants to merge 1 commit into
fastify:mainfrom
bcomnes:bret/allow-custom-content-type-recovery
Closed

bcomnes wants to merge 1 commit into
fastify:mainfrom
bcomnes:bret/allow-custom-content-type-recovery

Conversation

@bcomnes

@bcomnes bcomnes commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Keep malformed content types rejected by default while allowing an explicitly registered RegExp parser to recover known external values. Keep request handling independent of media type parsing so validation, normalization, and recovery remain encapsulated in the content type parser. Preserve existing catch-all and missing-route behavior.

Followup to #6414

Checklist

Keep malformed content types rejected by default while allowing an explicitly registered RegExp parser to recover known external values. Keep request handling independent of media type parsing so validation, normalization, and recovery remain encapsulated in the content type parser. Preserve existing catch-all and missing-route behavior.

Followup to fastify#6414
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 6, 2026
@bcomnes bcomnes mentioned this pull request Aug 7, 2026
4 tasks done

@climba03003 climba03003 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

RFC9110 noted that Content-Type must be singleton field, and may result in combined field value.
I would say we need a proper configuration to allows either first win or last win.

For example, how to deal with multiples different header.
text/plain, application/json
application/json, text/plain, application/json
It allows way too many situation for your fix.

Although Content-Type is defined as a singleton field, it is sometimes incorrectly generated multiple times, resulting in a combined field value that appears to be a list. Recipients often attempt to handle this error by using the last syntactically valid member of the list, leading to potential interoperability and security issues if different implementations have different error handling behaviors.

@bcomnes

bcomnes commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

I don't think a setting for that is appropriate. Have a single algorithm that does something vaguely sane by default and let users escape hatch to whatever they want.

A setting that's first or last win only isn't a flexible enough escape hatch. Not nessisary imo

@bcomnes

bcomnes commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Going to rework this, see #6414 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants