Giter Site home page Giter Site logo

media-typer's People

Contributors

carpasse avatar chocolateboy avatar dougwilson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

media-typer's Issues

not work with multipary/form-data boundary include slash

this is not working

multipart/form-data; boundary=b/QeEbFgqK9PCZo4T/eXv7f.T74SHd5MxCZ846AsTz-yNV0xrRR_Zks4fkNMCzJck9ZE8o

this ok

multipart/form-data; boundary=hQ9mmyU9285lg8QhbF7zuDmeuvc8flGel8sSgjHTBinO72dLucgB7oUOC3l6070sPpd1Es

Requests without content-type header make the module crash

In version 0.3.0, when you call the parse function and hand over a req object that has no content-type header set, this module crashes.

The problem is first located here, where getcontenttype is called. Then this calls this code, which simply returns undefined if the header is not there - which in turn leads to this error message.

I'm not that sure how to handle this case, but if you decide for an option, I'm happy to provide a PR.

Content-Types with parameters should not be invalid

Content-Type of application/xml; name=123 should be valid according to RFC 2045, Content-Types should support parameters type "/" subtype *(";" parameter)

However if you run var obj = typer.parse('application/xml; name=123')
you get the following error invalid media type

Two Content Types

This was more of an "info" for anyone who may come across this in the future.

A guy on the express gitter was trying to work out why body-parser.json() was not parsing his data.
What looked suspicious to me was his content-type being a double application/json.
Looked like the certain fetch library he was using was doing it.

Content-Type:  application/json, application/json

After digging and digging, via body-parser, type-is and finally media-typer I found it was a regular expression that was causing it to fail.
Read the rfc7231 from a link in another issue to find that two content types is not valid.
It makes sense, but until you actually KNOW it, you can never certain.

Just wanted to leave this hear in case someone else came along with something similar.

I didn't know if there was any sanity checking that could be done?

Should support both SPACE and HTAB as whitespace

Currently, the parse function can parse media types surrounded by whitespaces, but not tabs:

$ node
Welcome to Node.js v20.10.0.
Type ".help" for more information.
> var typer = require('media-typer')
undefined
> typer.parse("text/html ")
MediaType { type: 'text', subtype: 'html', suffix: undefined }
> typer.parse("text/html\t")
Uncaught TypeError: invalid media type
    at Object.parse (/mnt/wsl/tank/projects/type-is/node_modules/media-typer/index.js:117:11)
> 

However, I believe HTAB should be a valid whitespace character in the context of Content-Type header parsing. The specification for the Content-Type header (https://www.rfc-editor.org/rfc/rfc9110#field.content-type) states that:

The type/subtype MAY be followed by semicolon-delimited parameters (Section 5.6.6) in the form of name/value pairs.

And section 5.6.6 defines the semicolon-delimited parameters as:

  parameters      = *( OWS ";" OWS [ parameter ] )
  parameter       = parameter-name "=" parameter-value
  parameter-name  = token
  parameter-value = ( token / quoted-string )

Where OWS is defined in section 5.6.3 as:

  OWS            = *( SP / HTAB )
                 ; optional whitespace

So the media-type might be followed by HTABs in a valid Content-Type header. If the parser function supports trailing spaces, it should as well support trailing tabs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.