jshttp / accepts

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

*/* does not match text/* #18

Closed lkmill closed 5 years ago

lkmill commented 5 years ago
const accepts = require('accepts')

const accept = accepts({
  headers: {
    'accept': 'text/*',
  },
})

console.log(accept.types([ 'application/json', 'text/html' ])) // > text/html
console.log(accept.types([ 'application/json', '*/*' ])) // > false
dougwilson commented 5 years ago

This is because you cannot use partial types in the .types function (https://github.com/jshttp/accepts#typetypes):

The types array can contain full MIME types or file extensions.

What are you trying to accomplish with the above?

lkmill commented 5 years ago

ah, i see.

well i want the / to act as a catch all... essentially i want to return json if that matches the accept header, otherwise html.

https://github.com/midwest-js/responder/blob/master/index.js#L61

dougwilson commented 5 years ago

Would this work for your use-case? responses[req.accepts(['json']) || '*/*']

lkmill commented 5 years ago

now that i know i am using it wrong i was planning on implementing something like that, yes. thanks for your quick answers!

dougwilson commented 5 years ago

No problem!