eugef / node-mocks-http

Mock 'http' objects for testing Express routing functions
Other
747 stars 131 forks source link

`_isJSON()` doesn't recognize `application/*+json`. #238

Closed quoininc-huudatran closed 2 years ago

quoininc-huudatran commented 3 years ago

When setting Content-Type: application/hal+json, the response returns false for res_isJSON() call.

I would expect it to return true.

eugef commented 3 years ago

Hi @quoininc-huudatran, atm _isJSON() returns true only when Content-Type: application/json

But even if is-type library would be used - it will be still false because

typeIs.is('application/hal+json', 'json') === false

You can try it here https://runkit.com/embed/15jv0a7atjye

quoininc-huudatran commented 3 years ago

According to documentation of type-is:

A suffix such as +json. This can be combined with a wildcard such as */vnd+json or application/*+json. The full mime type will be returned if matched.

So we can do:

Boolean(typeIs.is('application/hal+json', ['json', 'application/*+json']))
eugef commented 3 years ago

You are right, please review the fix #243

github-actions[bot] commented 2 years ago

Stale issue message