mjackson / strata

A modular, streaming HTTP server for node.js
http://stratajs.org
366 stars 35 forks source link

content negotiation accept header q values #34

Open mvolkmann opened 12 years ago

mvolkmann commented 12 years ago

It would be nice if the content negotiation in Strata provided a way to get an ordered list of the media types a client accepts based on q values in the Accept header. For an example of a module that does this, see https://github.com/federomero/negotiator.

In this Accept header value ...

'text/json; q=0.1, text/plain; q=0.2, text/xml; q=0.3, text/html'

I would expect to get back

['text/html', 'text/xml', 'text/plain', 'text/json']

Media types with no q value, such as text/html in this example, default to 1. Then they are sorted in descending order.

mjackson commented 12 years ago

Indeed. I have a Ruby project, rack-accept, that does this. I've been thinking about porting this functionality over to strata, but nobody has needed it thus far.