jshttp / accepts

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

Type suffixes #10

Closed gausie closed 9 years ago

gausie commented 9 years ago

In my application, I am negotiation API version by an Accept header that follows the following structure:

application/vnd.<appName>.<version>+json

Is there a way of handling this with accepts? Should it match "json"?

dougwilson commented 9 years ago

There is some info on the readme. It matches"+json" as well as "application/*+json" :)

gausie commented 9 years ago

I can't see that information in the readme, and accepts is giving me a 406 with a Content-Type as described above.

Where does this check happen in the code?

dougwilson commented 9 years ago

Oops, sorry, in my haste to answer this question, I confused it with the type-is module, sorry! There is no way to use wildcards in this library, and this library also has no code doing any matching whatsoever as it is simply a wrapper for the negoiator module, which only accepts full types (and we sprinkle on file extensions, since we can made them to a finite list of types).

gausie commented 9 years ago

Phew! I was very confused :stuck_out_tongue_winking_eye:

Could we re-open this as an enhancement? Or should it be in negotiator?

I've solved it currently by asking clients to send application/vnd.<appName>.<version>+json,application/json but it seems quite wasteful.

dougwilson commented 9 years ago

Yes, it would need to be done in negotiator if we cannot form a finite list here, which for "anything ending in +json", it seems unlikely we can convert that into some finite list of exact mime types before calling negoiator.

There is always the option, btw, to call here without arguments, then you get a sorted list of the mimes and you can do whatever comparison you like, where the left most match is most preferred.