Socket
Socket
Sign inDemoInstall

type-is

Package Overview
Dependencies
3
Maintainers
6
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.7 to 1.6.0

6

HISTORY.md

@@ -0,1 +1,7 @@

1.6.0 / 2015-02-12
==================
* fix false-positives in `hasBody` `Transfer-Encoding` check
* support wildcard for both type and subtype (`*/*`)
1.5.7 / 2015-02-09

@@ -2,0 +8,0 @@ ==================

68

index.js

@@ -75,5 +75,4 @@

function hasbody(req) {
var headers = req.headers;
if ('transfer-encoding' in headers) return true;
return !isNaN(headers['content-length']);
return req.headers['transfer-encoding'] !== undefined
|| !isNaN(req.headers['content-length'])
}

@@ -147,11 +146,18 @@

switch (type) {
case 'urlencoded': return 'application/x-www-form-urlencoded';
case 'urlencoded':
type = 'application/x-www-form-urlencoded'
break
case 'multipart':
type = 'multipart/*';
break;
type = 'multipart/*'
break
}
return type[0] === '+' || ~type.indexOf('/')
? type
: mime.lookup(type)
if (type[0] === '+') {
// "+json" -> "*/*+json" expando
type = '*/*' + type
}
return type.indexOf('/') === -1
? mime.lookup(type)
: type
}

@@ -176,38 +182,28 @@

// exact match
if (expected === actual) {
return true
}
// split types
var actualParts = actual.split('/')
var expectedParts = expected.split('/')
actual = actual.split('/');
if (expected[0] === '+') {
// support +suffix
return Boolean(actual[1])
&& expected.length <= actual[1].length
&& expected === actual[1].substr(0 - expected.length)
// invalid format
if (actualParts.length !== 2 || expectedParts.length !== 2) {
return false
}
if (!~expected.indexOf('*')) return false;
expected = expected.split('/');
if (expected[0] === '*') {
// support */yyy
return expected[1] === actual[1]
// validate type
if (expectedParts[0] !== '*' && expectedParts[0] !== actualParts[0]) {
return false
}
if (expected[1] === '*') {
// support xxx/*
return expected[0] === actual[0]
// validate suffix wildcard
if (expectedParts[1].substr(0, 2) === '*+') {
return expectedParts[1].length <= actualParts[1].length + 1
&& expectedParts[1].substr(1) === actualParts[1].substr(1 - expectedParts[1].length)
}
if (expected[1][0] === '*' && expected[1][1] === '+') {
// support xxx/*+zzz
return expected[0] === actual[0]
&& expected[1].length <= actual[1].length + 1
&& expected[1].substr(1) === actual[1].substr(1 - expected[1].length)
// validate subtype
if (expectedParts[1] !== '*' && expectedParts[1] !== actualParts[1]) {
return false
}
return false
return true
}

@@ -214,0 +210,0 @@

{
"name": "type-is",
"description": "Infer the content-type of a request.",
"version": "1.5.7",
"version": "1.6.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",

@@ -6,0 +6,0 @@ "contributors": [

@@ -63,3 +63,3 @@ # type-is

- A mime type such as `application/json`.
- A mime type with a wildcard such as `*/json` or `application/*`. The full mime type will be returned if matched
- A mime type with a wildcard such as `*/*` or `*/json` or `application/*`. The full mime type will be returned if matched.
- 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.

@@ -66,0 +66,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc