Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify

Package Overview
Dependencies
Maintainers
2
Versions
289
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify - npm Package Compare versions

Comparing version 0.15.0 to 0.15.1

42

lib/tier-node.js

@@ -6,3 +6,2 @@ /* eslint-disable no-useless-return */

const runHooks = require('fastseries')()
const jsonParser = require('body/json')
const validation = require('./validation')

@@ -37,3 +36,3 @@ const validateSchema = validation.validate

if (req.headers['content-type'].indexOf('application/json') > -1) {
return jsonParser(req, bodyParsed(handle, params, req, res))
return jsonBody(req, res, params, handle)
// custom parser for a given content type

@@ -54,3 +53,3 @@ } else if (handle.contentTypeParser.fastHasHeader(req.headers['content-type'])) {

if (req.headers['content-type'] && req.headers['content-type'].indexOf('application/json') > -1) {
return jsonParser(req, bodyParsed(handle, params, req, res))
return jsonBody(req, res, params, handle)
// custom parser fir a given content type

@@ -72,13 +71,32 @@ } else if (handle.contentTypeParser.fastHasHeader(req.headers['content-type'])) {

function bodyParsed (handle, params, req, res) {
function parsed (err, body) {
if (err) {
res.statusCode = 422
setImmediate(wrapResEnd, res)
return
function jsonBody (req, res, params, handle) {
var body = ''
req.on('error', onError)
req.on('data', onData)
req.on('end', onEnd)
function onError (err) {
jsonBodyParsed(err, null, req, res, params, handle)
}
function onData (chunk) {
body += chunk
}
function onEnd () {
setImmediate(parse, body)
}
function parse (json) {
try {
jsonBodyParsed(null, JSON.parse(body), req, res, params, handle)
} catch (err) {
jsonBodyParsed(err, null, req, res, params, handle)
}
handler(handle, params, req, res, body, urlUtil.parse(req.url, true).query)
}
}
return parsed
function jsonBodyParsed (err, body, req, res, params, handle) {
if (err) {
res.statusCode = 422
setImmediate(wrapResEnd, res)
return
}
handler(handle, params, req, res, body, urlUtil.parse(req.url, true).query)
}

@@ -131,2 +149,2 @@

module.exports = build
module.exports[Symbol.for('internals')] = { bodyParsed, routerHandler, handler }
module.exports[Symbol.for('internals')] = { jsonBody, jsonBodyParsed, routerHandler, handler }
{
"name": "fastify",
"version": "0.15.0",
"version": "0.15.1",
"description": "Fast and low overhead web framework, for Node.js",

@@ -41,2 +41,3 @@ "main": "fastify.js",

"express": "^4.15.2",
"fast-json-body": "^1.1.0",
"fastify-plugin": "^0.1.0",

@@ -64,3 +65,2 @@ "frameguard": "^3.0.0",

"avvio": "^0.6.1",
"body": "^5.1.0",
"fast-json-stringify": "^0.10.4",

@@ -67,0 +67,0 @@ "fast-safe-stringify": "^1.1.13",

@@ -62,2 +62,6 @@ <div align="center">

Swagger documentation generator for Fastify
- [`fastify-multipart`](https://github.com/fastify/fastify-multipart)
Multipart support for Fastify
- [`fastify-bearer-auth`](https://github.com/jsumners/fastify-bearer-auth)
Bearer auth plugin for Fastify
- *More coming soon*

@@ -64,0 +68,0 @@

@@ -7,3 +7,3 @@ 'use strict'

const Fastify = require('..')
const jsonParser = require('body/json')
const jsonParser = require('fast-json-body')

@@ -10,0 +10,0 @@ test('contentTypeParser method should exist', t => {

@@ -24,8 +24,2 @@ /* eslint-disable no-useless-return */

test('bodyParsed function', t => {
t.plan(1)
const parsed = internals.bodyParsed(null, null, null, null)
t.is(typeof parsed, 'function')
})
test('handler function - invalid schema', t => {

@@ -32,0 +26,0 @@ t.plan(2)

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