Socket
Socket
Sign inDemoInstall

@pollyjs/adapter-node-http

Package Overview
Dependencies
26
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.1 to 6.0.0

23

package.json
{
"name": "@pollyjs/adapter-node-http",
"version": "5.1.1",
"version": "6.0.0",
"description": "Node HTTP adapter for @pollyjs",
"main": "dist/cjs/pollyjs-adapter-node-http.js",
"module": "dist/es/pollyjs-adapter-node-http.js",
"types": "types.d.ts",
"files": [

@@ -46,16 +47,16 @@ "src",

"dependencies": {
"@pollyjs/adapter": "^5.1.1",
"@pollyjs/utils": "^5.1.1",
"lodash-es": "^4.17.11",
"nock": "^12.0.3"
"@pollyjs/adapter": "^6.0.0",
"@pollyjs/utils": "^6.0.0",
"lodash-es": "^4.17.21",
"nock": "^13.2.1"
},
"devDependencies": {
"@pollyjs/core": "^5.1.1",
"@pollyjs/persister-fs": "^5.1.1",
"form-data": "^2.5.1",
"get-stream": "^5.1.0",
"node-fetch": "^2.6.0",
"@pollyjs/core": "^6.0.0",
"@pollyjs/persister-fs": "^6.0.0",
"form-data": "^4.0.0",
"get-stream": "^6.0.1",
"node-fetch": "^2.6.6",
"rollup": "^1.14.6"
},
"gitHead": "bd3f8196775dbdd424836aa7a8dffa6aa7adafc8"
"gitHead": "4c3f6e0970bf6170674749b9a45b928074f136c2"
}

@@ -32,8 +32,2 @@ import http from 'http';

static get name() {
// NOTE: deprecated in 4.1.0 but proxying since it's possible "core" is behind
// and therefore still referencing `name`. Remove in 5.0.0
return this.id;
}
onConnect() {

@@ -72,5 +66,5 @@ this.assert(

HTTP_METHODS.forEach(m => {
HTTP_METHODS.forEach((m) => {
// Add an intercept for each supported HTTP method that will match all paths
interceptor.intercept(/.*/, m).reply(function(_, _body, respond) {
interceptor.intercept(/.*/, m).reply(function (_, _body, respond) {
const { req, method } = this;

@@ -122,3 +116,3 @@ const { headers } = req;

// to set some default values which nock doesn't properly set.
Object.keys(modules).forEach(moduleName => {
Object.keys(modules).forEach((moduleName) => {
const module = modules[moduleName];

@@ -167,3 +161,3 @@ const { request, get, globalAgent } = module;

Object.keys(modules).forEach(moduleName => {
Object.keys(modules).forEach((moduleName) => {
const module = modules[moduleName];

@@ -183,8 +177,14 @@

} else {
pollyRequest[ABORT_HANDLER] = () => pollyRequest.abort();
pollyRequest[ABORT_HANDLER] = () => {
if (!pollyRequest.aborted && (req.aborted || req.destroyed)) {
pollyRequest.abort();
}
};
req.once('abort', pollyRequest[ABORT_HANDLER]);
req.once('close', pollyRequest[ABORT_HANDLER]);
}
}
async passthroughRequest(pollyRequest) {
async onFetchResponse(pollyRequest) {
const { parsedArguments } = pollyRequest.requestArguments;

@@ -210,3 +210,3 @@ const { method, headers, body } = pollyRequest;

// Write the request body
chunks.forEach(chunk => request.write(chunk));
chunks.forEach((chunk) => request.write(chunk));
request.end();

@@ -218,3 +218,3 @@

response.on('data', chunk => chunks.push(chunk));
response.on('data', (chunk) => chunks.push(chunk));
response.once('end', () =>

@@ -230,12 +230,13 @@ resolve(this.getBodyFromChunks(chunks, response.headers))

body: responseBody.body,
isBinary: responseBody.isBinary
encoding: responseBody.encoding
};
}
async respondToRequest(pollyRequest, error) {
async onRespond(pollyRequest, error) {
const { req, respond } = pollyRequest.requestArguments;
const { statusCode, body, headers, isBinary } = pollyRequest.response;
const { statusCode, body, headers, encoding } = pollyRequest.response;
if (pollyRequest[ABORT_HANDLER]) {
req.off('abort', pollyRequest[ABORT_HANDLER]);
req.off('close', pollyRequest[ABORT_HANDLER]);
}

@@ -259,3 +260,3 @@

const chunks = this.getChunksFromBody(body, headers, isBinary);
const chunks = this.getChunksFromBody(body, headers, encoding);
const stream = new ReadableStream();

@@ -266,3 +267,3 @@

// to be pushed to the response chunk by chunk.
chunks.forEach(chunk => stream.push(chunk));
chunks.forEach((chunk) => stream.push(chunk));
stream.push(null);

@@ -274,3 +275,3 @@

// the response was actually received.
const requestFinishedPromise = new Promise(resolve => {
const requestFinishedPromise = new Promise((resolve) => {
if (req.aborted) {

@@ -295,3 +296,3 @@ resolve();

if (isContentEncoded(headers)) {
const hexChunks = chunks.map(chunk => {
const encodedChunks = chunks.map((chunk) => {
if (!Buffer.isBuffer(chunk)) {

@@ -305,8 +306,8 @@ this.assert(

return chunk.toString('hex');
return chunk.toString('base64');
});
return {
isBinary: true,
body: JSON.stringify(hexChunks)
encoding: 'base64',
body: JSON.stringify(encodedChunks)
};

@@ -319,11 +320,11 @@ }

// The merged buffer can be one of two things:
// 1. A binary buffer which then has to be recorded as a hex string.
// 1. A binary buffer which then has to be recorded as a base64 string.
// 2. A string buffer.
return {
isBinary: isBinaryBuffer,
body: buffer.toString(isBinaryBuffer ? 'hex' : 'utf8')
encoding: isBinaryBuffer ? 'base64' : undefined,
body: buffer.toString(isBinaryBuffer ? 'base64' : 'utf8')
};
}
getChunksFromBody(body, headers, isBinary = false) {
getChunksFromBody(body, headers, encoding) {
if (!body) {

@@ -338,14 +339,14 @@ return [];

// If content-encoding is set in the header then the body/content
// is as an array of hex strings
// is as an array of base64 strings
if (isContentEncoded(headers)) {
const hexChunks = JSON.parse(body);
const encodedChunks = JSON.parse(body);
return hexChunks.map(chunk => Buffer.from(chunk, 'hex'));
return encodedChunks.map((chunk) => Buffer.from(chunk, encoding));
}
// The body can be one of two things:
// 1. A hex string which then means its binary data.
// 1. A base64 string which then means its binary data.
// 2. A utf8 string which means a regular string.
return [Buffer.from(body, isBinary ? 'hex' : 'utf8')];
return [Buffer.from(body, encoding ? encoding : 'utf8')];
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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