Skip to content

AcceptHeader::fromString() not fully compliant with the related RFC9110? #62282

@andesk

Description

@andesk

Symfony version(s) affected

7.4, 7.3, most likely earlier versions as well (did not check, but I doubt that valid behavior was broken later on)

Description

The mentioned method is "loosing" important negotiation information when there is more than one accepted type given with different additional attributes/parameters. Think of text/plain;format=flowed and text/plain;format=fixed;q=0.4 (example from RFC9110, https://www.rfc-editor.org/rfc/rfc9110.html#name-accept). AcceptHeader::fromString() will contain solely text/plain;format=fixed;q=0.4 and forget/ignore text/plain;format=flowed with its quality of 1.0 (fallback value if not specified).

The reason for that is that internally, the AcceptHeader::add() method is using solely $item->getValue() as the array key of AcceptHeaderItems added, ignoring any other attributes. So the last "value" overwrites all others.

Fixing that might lead to a BC break potentially, as the behavior would change for such cases. But as it seems that this issue has not been raised before, the question is if it still could/should be fixed? Also the aspect of "Media ranges can be overridden by more specific media ranges or specific media types. If more than one media range applies to a given type, the most specific reference has precedence." would be needed to be taken into account 🤔

How to reproduce

I've copied some example Accept headers from the related RFC9110 and its predecessor RFC7231 into the available unit tests in a created branch: 7.4...andesk:symfony:bug-reproduction/accept-header-from-string The misalignment should be visible with the according tests breaking.

Possible Solution

Creating a different array key appending attribute key+value pairs to its string representation somehow to avoid overriding existing value expectations for other attribute combinations.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions