jshttp / negotiator

An HTTP content negotiator for Node.js
MIT License
309 stars 33 forks source link

[Question] parseMediaType(), and parameters after q-value #57

Closed AnyhowStep closed 5 years ago

AnyhowStep commented 5 years ago

I was just curious about why parseMediaType() doesn't parse parameters after the q value,

https://github.com/jshttp/negotiator/blob/99f418e11907b60e63f0addc09fc596ddc7be5be/lib/mediaType.js#L75-L78

//key before q
preferredMediaTypes("a/a;q=1, b/b;key=*;q=1", ["a/a","b/b"])
//b/b more preferred
//["b/b", "a/a"]

//key after q
preferredMediaTypes("a/a;q=1, b/b;q=1;key=*", ["a/a","b/b"])
//a/a more preferred
//["a/a", "b/b"]
dougwilson commented 5 years ago

Parameters are only those before the q. https://tools.ietf.org/html/rfc7231#section-5.3.2

AnyhowStep commented 5 years ago

I see.

I also noticed there's an optional accept-ext part that comes after the q that looks syntactically the same as the parameters part.

I couldn't find the purpose of accept-ext in that RFC, though.

dougwilson commented 5 years ago

It's effectively useless and an historical artifact.

AnyhowStep commented 5 years ago

Ah, all right. Thanks!