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

fastify-raw-body

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-raw-body - npm Package Compare versions

Comparing version 4.2.2 to 4.3.0

4

package.json
{
"name": "fastify-raw-body",
"version": "4.2.2",
"version": "4.3.0",
"description": "Request raw body",

@@ -40,3 +40,3 @@ "main": "plugin.js",

"tap": "^16.2.0",
"tsd": "^0.28.0"
"tsd": "^0.29.0"
},

@@ -43,0 +43,0 @@ "dependencies": {

@@ -22,2 +22,3 @@ import { FastifyPluginCallback } from 'fastify'

routes?: string[]
jsonContentTypes?: string[]
}

@@ -24,0 +25,0 @@

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

const { field, encoding, global, runFirst, routes } = Object.assign({
const { field, encoding, global, runFirst, routes, jsonContentTypes } = Object.assign({
field: 'rawBody',

@@ -21,7 +21,8 @@ encoding: 'utf8',

runFirst: false,
routes: []
routes: [],
jsonContentTypes: ['application/json']
}, opts)
if (encoding === false) {
fastify.addContentTypeParser('application/json',
fastify.addContentTypeParser(jsonContentTypes,
{ parseAs: 'buffer' },

@@ -28,0 +29,0 @@ almostDefaultJsonParser)

@@ -39,3 +39,4 @@ # fastify-raw-body

runFirst: true, // get the body before any preParsing hook change/uncompress it. **Default false**
routes: [] // array of routes, **`global`** will be ignored, wildcard routes not supported
routes: [], // array of routes, **`global`** will be ignored, wildcard routes not supported
jsonContentTypes: [], // array of content-types to handle as JSON. **Default ['application/json']**
})

@@ -42,0 +43,0 @@

@@ -417,2 +417,25 @@ 'use strict'

t.test('raw body alternative content-type (application/ld+json)', async t => {
const app = Fastify()
const payload = { hello: 'world' }
await app.register(rawBody, { encoding: false, jsonContentTypes: ['application/ld+json'] })
app.post('/', (req, reply) => {
t.same(req.body, { hello: 'world' })
t.type(req.rawBody, Buffer)
reply.send(req.rawBody)
})
const res = await app.inject({
method: 'POST',
url: '/',
headers: { 'content-type': 'application/ld+json' },
payload
})
t.equal(res.statusCode, 200)
t.equal(res.payload, JSON.stringify(payload))
})
t.test('body limit', async t => {

@@ -419,0 +442,0 @@ const app = Fastify({ bodyLimit: 5 })

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