Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for HTAB as well as SP as whitespace separators in content-type headers #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rg2011
Copy link

@rg2011 rg2011 commented Jan 28, 2024

Fixes issue #52. Notes:

  • The fix applies to both typeis and typeis.is, instead of just typeis.

    This is because typeis.is can receive a req-like or res-like object (this behaviour is undocumented but tested). I wanted to avoid situations where typeis(req, ...) would work but typeis.is(req, ...) would not.

  • The fix breaks backward compatibility in that, previously, typeis would fail if the content-type parameters were not properly formatted. But, after this PR, it will just ignore them.

    i.e. previously, this would return false:

    typeis.is('application/json; charset:utf-8', 'json') // Notice the ":" instead of "=" in charset

    But after this PR, it will return "json".

    This behaviour was documented (...If the Content-Type header is invalid...):

    type-is/README.md

    Lines 35 to 38 in 7d19b7a

    Checks if the `request` is one of the `types`. If the request has no body,
    even if there is a `Content-Type` header, then `null` is returned. If the
    `Content-Type` header is invalid or does not matches any of the `types`, then
    `false` is returned. Otherwise, a string of the type that matched is returned.

    But it was not tested in the case of invalid parameters. I am not sure of the best way forward:

    • Keep validating parameters, and make test cases for it,
    • Or update the documentation to clarify that parameters will not be validated.
  • After this PR, media-typer dependency could be upgraded to 1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant