Socket
Socket
Sign inDemoInstall

co-body

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-body - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

7

History.md
3.1.0 / 2015-08-06
==================
* travis: add v2, v3, remove 0.11
* add custom types options
* use type-is
3.0.0 / 2015-07-25

@@ -3,0 +10,0 @@ ==================

26

lib/any.js

@@ -6,2 +6,3 @@

var typeis = require('type-is')
var json = require('./json');

@@ -11,9 +12,5 @@ var form = require('./form');

var JSON_CONTENT_TYPES = [
'application/json',
'application/json-patch+json',
'application/vnd.api+json',
'application/csp-report',
'application/ld+json'
];
var jsonTypes = ['json', 'application/*+json', 'application/csp-report'];
var formTypes = ['urlencoded']
var textTypes = ['text']

@@ -35,18 +32,19 @@ /**

req = req.req || req;
opts = opts || {};
// parse Content-Type
var type = req.headers['content-type'] || '';
type = type.split(';')[0];
// json
if (~JSON_CONTENT_TYPES.indexOf(type)) return json(req, opts);
var jsonType = opts.jsonTypes || jsonTypes;
if (typeis(req, jsonType)) return json(req, opts);
// form
if ('application/x-www-form-urlencoded' == type) return form(req, opts);
var formType = opts.formTypes || formTypes;
if (typeis(req, formType)) return form(req, opts);
// text
if ('text/plain' == type) return text(req, opts);
var textType = opts.textTypes || textTypes;
if (typeis(req, textType)) return text(req, opts);
// invalid
return function(done){
var type = req.headers['content-type'] || '';
var message = type ? 'Unsupported content-type: ' + type : 'Missing content-type';

@@ -53,0 +51,0 @@ var err = new Error(message);

{
"name": "co-body",
"version": "3.0.0",
"version": "3.1.0",
"repository": "cojs/co-body",

@@ -17,3 +17,4 @@ "description": "request body parsing for co",

"qs": "~4.0.0",
"raw-body": "~2.1.2"
"raw-body": "~2.1.2",
"type-is": "~1.6.6"
},

@@ -32,3 +33,6 @@ "devDependencies": {

},
"files": ["index.js", "lib/"]
"files": [
"index.js",
"lib/"
]
}

@@ -34,2 +34,5 @@

- `queryString` an object of options when parsing query strings and form data. See [qs](https://github.com/hapijs/qs) for more information.
- `jsonTypes` is used to determine what media type **co-body** will parse as **json**, this option is passed directly to the [type-is](https://github.com/jshttp/type-is) library.
- `formTypes` is used to determine what media type **co-body** will parse as **form**, this option is passed directly to the [type-is](https://github.com/jshttp/type-is) library.
- `textTypes` is used to determine what media type **co-body** will parse as **text**, this option is passed directly to the [type-is](https://github.com/jshttp/type-is) library.

@@ -55,2 +58,5 @@ more options available via [raw-body](https://github.com/stream-utils/raw-body#getrawbodystream-options-callback):

var body = yield parse(req);
// custom type
var body = yield parse(req, { textTypes: ['text', 'html'] });
```

@@ -57,0 +63,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc