jshttp / accepts

Higher-level content negotiation
MIT License
252 stars 42 forks source link

Accept types always validating #4

Closed yanickrochon closed 10 years ago

yanickrochon commented 10 years ago

I'm trying to use this in Koa.js and the results are indeterministic.

For example

// "normal" browser request (Chrome)
// accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
this.request.accept.types('json');   // -> 'json'
this.request.accept.types('html');   // -> 'html'

// ajax ($.getJSON) request with jQuery (Chrome)
// accept: application/json, text/javascript, */*; q=0.01
this.request.accept.types('json');   // -> 'json'
this.request.accept.types('html');   // -> 'html'

there should be a strict mode, or something. How can the program determine accurately what response type to return?

defunctzombie commented 10 years ago

Seems to be working as designed. If you want priority to matter you need to specify multiple types in a single call. See the readme.

dougwilson commented 10 years ago

If the Accept header contains */* it is saying it accepts anything. You need to pass all your types in at once in a singe array and see which type is accepts most.