jshttp / content-type

Create and parse HTTP Content-Type header
MIT License
131 stars 25 forks source link

[Bug] Throw invalid parameter format error when no charset property #15

Closed alberthuang24 closed 4 years ago

alberthuang24 commented 4 years ago

Examles

let headers = [
  'content-type': 'text/html;'
];

contentType.parse(headers['content-type']);

image

But according to HTTP RFC, this is a legal content type.

dougwilson commented 4 years ago

The trailing semicolon is the invalid part; parameters start with a semicolon if you follow the ABNF in the standard, so that header looks like a parameter started but was just truncated.

ABNF from RFC 7231:

media-type = type "/" subtype *( OWS ";" OWS parameter )
alberthuang24 commented 4 years ago

image

This is the original content-type