jshttp / type-is

Infer the content-type of a request.
MIT License
226 stars 32 forks source link

Content type with profile not matching as expected #44

Closed wmurphyrd closed 4 years ago

wmurphyrd commented 4 years ago

Version 1.6.18

typeIs.is('application/ld+json; profile="https://www.w3.org/ns/activitystreams"', ['application/ld+json; profile="https://www.w3.org/ns/activitystreams"'])

Evaluates to false. It seems to use different normalization methods for value and type

dougwilson commented 4 years ago

This is because what you provided as the types argument is not valid. You can find the list of allowed strings in that array in the documentation here: https://github.com/jshttp/type-is#typeisismediatype-types

dougwilson commented 4 years ago

There is an open issue #14 to support parameters in the types argument, which I think is what you're asking to support.

wmurphyrd commented 4 years ago

Ah thanks. I'm just trying to implement this W3 spec. I'm sure It will work fine without specifying the profile in my types list

dougwilson commented 4 years ago

Gotcha, makes sense. So yes, this library doesn't let you match on the parameters. The only way you can do it currently is to include the content-type library to get the library:

var contentType = require('content-type')
var typeis = require('type-is')

// ... later on

if (typeis(req, 'application/ld+json') && contentType.parse(req).parameters.profile === 'https://www.w3.org/ns/activitystreams') {
  // accepts that specific thing
}