Socket
Socket
Sign inDemoInstall

nock

Package Overview
Dependencies
4
Maintainers
4
Versions
422
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 14.0.0-beta.3 to 14.0.0-beta.4

48

lib/create_response.js
'use strict'
const zlib = require('node:zlib')
const { headersArrayToObject } = require('./common')
const { STATUS_CODES } = require('http')
const { pipeline, Readable } = require('node:stream')

@@ -19,5 +21,32 @@ /**

/**
* @param {IncomingMessage} message
* @param {import('node:http').IncomingMessage} message
*/
function createResponse(message) {
// https://github.com/Uzlopak/undici/blob/main/lib/fetch/index.js#L2031
const decoders = []
const codings =
message.headers['content-encoding']
?.toLowerCase()
.split(',')
.map(x => x.trim())
.reverse() || []
for (const coding of codings) {
if (coding === 'gzip' || coding === 'x-gzip') {
decoders.push(
zlib.createGunzip({
flush: zlib.constants.Z_SYNC_FLUSH,
finishFlush: zlib.constants.Z_SYNC_FLUSH,
}),
)
} else if (coding === 'deflate') {
decoders.push(zlib.createInflate())
} else if (coding === 'br') {
decoders.push(zlib.createBrotliDecompress())
} else {
decoders.length = 0
break
}
}
const chunks = []
const responseBodyOrNull = responseStatusCodesWithoutBody.includes(

@@ -29,4 +58,17 @@ message.statusCode,

start(controller) {
message.on('data', chunk => controller.enqueue(chunk))
message.on('end', () => controller.close())
message.on('data', chunk => chunks.push(chunk))
message.on('end', () => {
pipeline(
Readable.from(chunks),
...decoders,
async function* (source) {
for await (const chunk of source) {
yield controller.enqueue(chunk)
}
},
error => {
error ? controller.error(error) : controller.close()
},
)
})

@@ -33,0 +75,0 @@ /**

4

package.json

@@ -10,3 +10,3 @@ {

],
"version": "14.0.0-beta.3",
"version": "14.0.0-beta.4",
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",

@@ -21,3 +21,3 @@ "repository": {

"engines": {
"node": ">= 10.13"
"node": ">= 18"
},

@@ -24,0 +24,0 @@ "main": "./index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc