Git Product home page Git Product logo

content-type's People

Contributors

bbamsch avatar carpasse avatar commanderroot avatar dougwilson avatar gr0uch avatar marswong 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  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  avatar  avatar  avatar

content-type's Issues

double quotes seemingly required for profile parameter

I'm using content-type to extract the profile parameter. According to the spec, the URI may be enclosed in either single or double quotes (or not at all). However, the current version is throwing an error in all cases except for double quotes.

how to catch parsing errors

Hi

How would you use this module for parsing content-types expecting that it might throw errors. Is it correct that you either have to try/catch or use Promise ? E.g. for synchronous usage something like this:

var parsed;
try {
    parsed = contentType.parse(type);
}
catch (e){
    console.log(type);
    console.log(href);
    console.error(e.stack);
}

I often use the request module and test against httpbin.org. This http://httpbin.org/response-headers?Content-Type=text%2Fplain%3B+charset%3DUTF-8&Server=httpbin throws the following error:

text%2Fplain%3B charset%3DUTF-8
http://httpbin.org/response-headers?Content-Type=text%2Fplain%3B+charset%3DUTF-8&Server=httpbin
TypeError: invalid media type
    at parse (node_modules/content-type/index.js:128:11)
    ...

I could solve by using decodeURIComponent, something like: contentType.parse(decodeURIComponent(type)); but is this the recommended usage?

Content-Type checking less restrictive than RFC 6838 spec

According to RFC 6838 spec, content-type naming should follow ABNF format as shown...

Type and subtype names MUST conform to the following ABNF:

type-name = restricted-name
subtype-name = restricted-name

restricted-name = restricted-name-first *126restricted-name-chars
restricted-name-first  = ALPHA / DIGIT
restricted-name-chars  = ALPHA / DIGIT / "!" / "#" /
                         "$" / "&" / "-" / "^" / "_"
restricted-name-chars =/ "." ; Characters before first dot always
                             ; specify a facet name
restricted-name-chars =/ "+" ; Characters after last plus always
                             ; specify a structured syntax suffix

Current (as of commit c9da3ac) content type regular expression is less restrictive than specified above.

For example, the following characters are considered valid during type checking while they do not appear in RFC 6838:

  • %
  • '
  • *
  • `
  • |
  • ~

To conform with RFC 6838 spec, the following changes should be made...

  • Should enforce ALPHA / DIGIT exclusively for first character in type-name & subtype-name
  • Should not accept excess characters (%'*`|~)
  • Should restrict length to at most 127 characters in type-name & subtype-name (1 restricted-name-first and 0 to 126 restricted-name-chars)

Invalid parameter format reading Amazon AVS multipart headers

I am using Amazon AVS, which is returning a content type header of ":"multipart/related; boundary=------abcde123; type=application/json". The package throws a TypeError('invalid parameter format').

It appears to be the trailing "/json" which is causing the issue (manually removing it fixes the problem).

lchown /node_modules/content-type/HISTORY.md: invalid argument.

I have a docker image that includes an express server v4.18.2. It's failing on HISTORY.md every time.

4e7e0215f4ad: Pull complete
f206d87fdd12: Pull complete
5d2b14b7402b: Pull complete
85cbc4392f0e: Pull complete
77411fe1f4da: Pull complete
23f844e44e9e: Pull complete
4334efab300b: Pull complete
6496e772977a: Pull complete
3877be6b3e68: Pull complete
b65ae8fc6c48: Extracting [==================================================>] 26.25MB/26.25MB
3be3ca4d8f67: Download complete
02847af5dbd7: Download complete
4397228b905c: Download complete
docker: failed to register layer: Error processing tar file(exit status 1): lchown /node_modules/content-type/HISTORY.md: invalid argument.

Do you need to `type.toLowerCase()`?

index.js#L135

  var obj = new ContentType(type.toLowerCase())

According to the spec, the type and subtype are not case-sensitive, fair-enough

The type, subtype, and parameter names are not case sensitive. For example, TEXT, Text, and TeXt are all equivalent. Parameter values are normally case sensitive, but certain parameters are interpreted to be case- insensitive, depending on the intended use. (For example, multipart boundaries are case-sensitive, but the "access- type" for message/External-body is not case-sensitive.)

However, it doesn't specify that it needs to be lowercased, why make it? I was just testing with ExpressJS and saw that the content-type header's value is the only one being lowercased. It almost feels like it's the client's job to ignore the case.

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.