jshttp / negotiator

An HTTP content negotiator for Node.js
MIT License
315 stars 36 forks source link

Negotiator behavior on duplicate accept content-types #48

Open zeronone opened 8 years ago

zeronone commented 8 years ago

What is the expected behavior if there are duplicate content-types inside the Accept header.

var n = Negotiator({ headers: { accept: "application/json, application/xml, application/json" } });
n.mediaTypes();
// [ 'application/json', 'application/xml', 'application/json' ]
n.mediaTypes(['application/json', 'application/xml']);
// ['application/xml', 'application/json']
n.mediaTypes(['application/*']);
// []
n.mediaTypes(['*/*']);
// []

Does the preference of application/json decreases due to duplication? And the availableMediaTypes given to the mediaTypes() should be concrete concrete types?

dougwilson commented 8 years ago

Hi @zeronone, for the first question, I need to consult the specifications to determine what exactly the behavior should be.

For your question about the concrete types, yes, the server must supply concrete types, while it is the client that can supply wildcards. This is because a server will have a set of actual concrete things it can send back to a client, while a client can ask for various different types. The formulation of these algorithms is specified in various HTTP RFCs.