Skip to content
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

Content negotiation does not take into account media type parameters #963

Closed
raboof opened this issue Mar 14, 2017 · 3 comments
Closed

Content negotiation does not take into account media type parameters #963

raboof opened this issue Mar 14, 2017 · 3 comments
Labels
t:marshalling t:routing Issues related to the routing DSL t:server Issues related to the HTTP server
Milestone

Comments

@raboof
Copy link
Member

raboof commented Mar 14, 2017

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 describes how content negotiation should work when responding to requests with an Accept header. The current implementation doesn't appear to take into account media type parameters.

raboof added a commit to raboof/akka-http that referenced this issue Mar 14, 2017
https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 describes how
to interpret the Accept header during content negotiation.

Notably, it specifies "The media type quality factor associated with a given
type is determined by finding the media range with the highest precedence which
matches that type", and then gives some examples.

'matching' is implemented in akka-http in `MediaRange::matches`, but for
`MediaRange.One` fails to take into account parameters.

'precedence' is implemented in akka-http when determining the sorting of
`acceptedMediaRanges` in `MediaTypeNegotiator`, but for non-wildcard media
types sorts by the qValue instead of by the number of parameters.
@jrudolph jrudolph added 3 - in progress Someone is working on this ticket t:marshalling t:routing Issues related to the routing DSL t:server Issues related to the HTTP server labels Mar 15, 2017
@jrudolph
Copy link
Member

Hey @raboof, good to have you here ;)

Thanks for tackling this. IIRC it was mentioned somewhere before but I cannot seem to find the place.

@ktoso ktoso modified the milestones: 10.0.x, 10.0.6 Mar 17, 2017
raboof added a commit that referenced this issue Apr 13, 2017
* Use media type parameters in content negotiation (#963)

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 describes how
to interpret the Accept header during content negotiation.

Notably, it specifies "The media type quality factor associated with a given
type is determined by finding the media range with the highest precedence which
matches that type", and then gives some examples.

'matching' is implemented in akka-http in `MediaRange::matches`, but for
`MediaRange.One` and custom media ranges fails to take into account parameters.

'precedence' is implemented in akka-http when determining the sorting of
`acceptedMediaRanges` in `MediaTypeNegotiator`, but for non-wildcard media
types sorts only by the qValue ignoring the parameters.

We do want to take into account the `qValue` when determining the
order of `acceptedMediaRanges`, to make sure to select the right one when
encountering a media type that matches multiple ranges with the same
specificity but a different qValue. The specificity (number of parameters)
should have precedence though.
@jrudolph jrudolph modified the milestones: 10.0.6, 10.0.7 May 3, 2017
@ktoso
Copy link
Member

ktoso commented May 24, 2017

Can we close this as solved? The linked PR had some minor questions but seems to fix this

@ktoso ktoso modified the milestones: 10.0.7, 10.0.8 May 24, 2017
@jrudolph
Copy link
Member

jrudolph commented May 24, 2017

I think we just forgot to close.

@jrudolph jrudolph modified the milestones: 10.0.7, 10.0.8 May 24, 2017
@ktoso ktoso removed 3 - in progress Someone is working on this ticket labels May 24, 2017
tomrf1 pushed a commit to tomrf1/akka-http that referenced this issue Aug 13, 2017
* Use media type parameters in content negotiation (akka#963)

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 describes how
to interpret the Accept header during content negotiation.

Notably, it specifies "The media type quality factor associated with a given
type is determined by finding the media range with the highest precedence which
matches that type", and then gives some examples.

'matching' is implemented in akka-http in `MediaRange::matches`, but for
`MediaRange.One` and custom media ranges fails to take into account parameters.

'precedence' is implemented in akka-http when determining the sorting of
`acceptedMediaRanges` in `MediaTypeNegotiator`, but for non-wildcard media
types sorts only by the qValue ignoring the parameters.

We do want to take into account the `qValue` when determining the
order of `acceptedMediaRanges`, to make sure to select the right one when
encountering a media type that matches multiple ranges with the same
specificity but a different qValue. The specificity (number of parameters)
should have precedence though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t:marshalling t:routing Issues related to the routing DSL t:server Issues related to the HTTP server
Projects
None yet
Development

No branches or pull requests

3 participants