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

@mswjs/interceptors

Package Overview
Dependencies
Maintainers
1
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mswjs/interceptors - npm Package Compare versions

Comparing version 0.16.4 to 0.16.5

50

lib/interceptors/ClientRequest/NodeClientRequest.js

@@ -133,3 +133,2 @@ "use strict";

NodeClientRequest.prototype.write = function () {
var _this = this;
var args = [];

@@ -141,27 +140,15 @@ for (var _i = 0; _i < arguments.length; _i++) {

this.log('write:', { chunk: chunk, encoding: encoding, callback: callback });
this.chunks.push({
chunk: chunk,
encoding: encoding,
callback: function (error) {
_this.log('executing custom callback...');
if (error) {
_this.log('error while writing chunk!', error);
}
else {
_this.log('request chunk successfully written!');
}
/**
* Prevent invoking the callback if the written chunk is empty.
* @see https://nodejs.org/api/http.html#requestwritechunk-encoding-callback
*/
if (!chunk || chunk.length === 0) {
_this.log('written chunk is empty, skipping callback...');
return;
}
_this.log('executing custom write callback:', callback);
callback === null || callback === void 0 ? void 0 : callback(error);
},
});
this.chunks.push({ chunk: chunk, encoding: encoding });
this.requestBody = concatChunkToBuffer_1.concatChunkToBuffer(chunk, this.requestBody);
this.log('chunk successfully stored!', this.requestBody);
/**
* Prevent invoking the callback if the written chunk is empty.
* @see https://nodejs.org/api/http.html#requestwritechunk-encoding-callback
*/
if (!chunk || chunk.length === 0) {
this.log('written chunk is empty, skipping callback...');
}
else {
callback === null || callback === void 0 ? void 0 : callback();
}
// Do not write the request body chunks to prevent

@@ -257,6 +244,9 @@ // the Socket from sending data to a potentially existing

for (var _d = __values(_this.chunks), _e = _d.next(); !_e.done; _e = _d.next()) {
var _f = _e.value, chunk_1 = _f.chunk, encoding_1 = _f.encoding, callback_1 = _f.callback;
encoding_1
? _super.prototype.write.call(_this, chunk_1, encoding_1, callback_1)
: _super.prototype.write.call(_this, chunk_1, callback_1);
var _f = _e.value, chunk_1 = _f.chunk, encoding_1 = _f.encoding;
if (encoding_1) {
_super.prototype.write.call(_this, chunk_1, encoding_1);
}
else {
_super.prototype.write.call(_this, chunk_1);
}
}

@@ -330,3 +320,3 @@ }

this.emit('response-internal', secondClone);
this.log('response successfuly cloned, emitting "response" event...');
this.log('response successfully cloned, emitting "response" event...');
return _super.prototype.emit.apply(this, __spreadArray([event, firstClone], __read(data.slice(1))));

@@ -343,3 +333,3 @@ }

this.log('error:\n', error);
// Supress certain errors while using the "mock" source.
// Suppress certain errors while using the "mock" source.
// For example, no need to destroy this request if it connects

@@ -346,0 +336,0 @@ // to a non-existing hostname but has a mocked response.

4

package.json
{
"name": "@mswjs/interceptors",
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.",
"version": "0.16.4",
"version": "0.16.5",
"main": "lib/index.js",

@@ -42,2 +42,3 @@ "typings": "lib/index.d.ts",

"@types/express-rate-limit": "^6.0.0",
"@types/follow-redirects": "^1.14.1",
"@types/jest": "^27.0.3",

@@ -55,2 +56,3 @@ "@types/node": "^16.11.26",

"express-rate-limit": "^6.3.0",
"follow-redirects": "^1.15.1",
"got": "^11.8.3",

@@ -57,0 +59,0 @@ "jest": "^27.4.3",

@@ -58,3 +58,2 @@ import type { Debugger } from 'debug'

encoding?: BufferEncoding
callback?: ClientRequestWriteCallback
}> = []

@@ -93,32 +92,16 @@ private responseSource: 'mock' | 'bypass' = 'mock'

this.log('write:', { chunk, encoding, callback })
this.chunks.push({
chunk,
encoding,
callback: (error?: Error | null) => {
this.log('executing custom callback...')
if (error) {
this.log('error while writing chunk!', error)
} else {
this.log('request chunk successfully written!')
}
/**
* Prevent invoking the callback if the written chunk is empty.
* @see https://nodejs.org/api/http.html#requestwritechunk-encoding-callback
*/
if (!chunk || chunk.length === 0) {
this.log('written chunk is empty, skipping callback...')
return
}
this.log('executing custom write callback:', callback)
callback?.(error)
},
})
this.chunks.push({ chunk, encoding })
this.requestBody = concatChunkToBuffer(chunk, this.requestBody)
this.log('chunk successfully stored!', this.requestBody)
/**
* Prevent invoking the callback if the written chunk is empty.
* @see https://nodejs.org/api/http.html#requestwritechunk-encoding-callback
*/
if (!chunk || chunk.length === 0) {
this.log('written chunk is empty, skipping callback...')
} else {
callback?.()
}
// Do not write the request body chunks to prevent

@@ -235,6 +218,8 @@ // the Socket from sending data to a potentially existing

for (const { chunk, encoding, callback } of this.chunks) {
encoding
? super.write(chunk, encoding, callback)
: super.write(chunk, callback)
for (const { chunk, encoding } of this.chunks) {
if (encoding) {
super.write(chunk, encoding)
} else {
super.write(chunk)
}
}

@@ -302,3 +287,3 @@

this.log('response successfuly cloned, emitting "response" event...')
this.log('response successfully cloned, emitting "response" event...')
return super.emit(event, firstClone, ...data.slice(1))

@@ -317,3 +302,3 @@ } catch (error) {

// Supress certain errors while using the "mock" source.
// Suppress certain errors while using the "mock" source.
// For example, no need to destroy this request if it connects

@@ -320,0 +305,0 @@ // to a non-existing hostname but has a mocked response.

Sorry, the diff of this file is not supported yet

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