jshttp / type-is

Infer the content-type of a request.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Content type with profile not matching as expected

wmurphyrd opened this issue · comments

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

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

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

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

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
}