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

mimic-response

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mimic-response - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

4

index.d.ts

@@ -13,6 +13,6 @@ import {IncomingMessage} from 'http';

declare function mimicResponse<T extends NodeJS.ReadableStream>(
fromStream: IncomingMessage,
fromStream: IncomingMessage, // eslint-disable-line @typescript-eslint/prefer-readonly-parameter-types
toStream: T,
): IncomingMessage & T;
): T & IncomingMessage;
export = mimicResponse;

@@ -9,3 +9,2 @@ 'use strict';

'complete',
'destroy',
'headers',

@@ -29,2 +28,4 @@ 'httpVersion',

const properties = {};
for (const property of fromProperties) {

@@ -36,6 +37,24 @@ // Don't overwrite existing properties.

toStream[property] = typeof fromStream[property] === 'function' ? fromStream[property].bind(fromStream) : fromStream[property];
properties[property] = {
get() {
const value = fromStream[property];
const isFunction = typeof value === 'function';
return isFunction ? value.bind(fromStream) : value;
},
set(value) {
fromStream[property] = value;
},
enumerable: true,
configurable: false
};
}
Object.defineProperties(toStream, properties);
fromStream.once('aborted', () => {
toStream.emit('aborted');
});
return toStream;
};
{
"name": "mimic-response",
"version": "2.1.0",
"version": "3.0.0",
"description": "Mimic a Node.js HTTP response stream",

@@ -14,3 +14,3 @@ "license": "MIT",

"engines": {
"node": ">=8"
"node": ">=10"
},

@@ -35,10 +35,10 @@ "scripts": {

"devDependencies": {
"@sindresorhus/tsconfig": "^0.3.0",
"@types/node": "^12.0.0",
"ava": "^1.1.0",
"@types/node": "^14.0.1",
"ava": "^2.4.0",
"create-test-server": "^2.4.0",
"pify": "^4.0.1",
"tsd": "^0.7.3",
"xo": "^0.24.0"
"p-event": "^4.1.0",
"pify": "^5.0.0",
"tsd": "^0.11.0",
"xo": "^0.30.0"
}
}

@@ -1,2 +0,2 @@

# mimic-response [![Build Status](https://travis-ci.org/sindresorhus/mimic-response.svg?branch=master)](https://travis-ci.org/sindresorhus/mimic-response)
# mimic-response [![Build Status](https://travis-ci.com/sindresorhus/mimic-response.svg?branch=master)](https://travis-ci.com/sindresorhus/mimic-response)

@@ -30,2 +30,51 @@ > Mimic a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage)

**Note #1:** The `from.destroy(error)` function is not proxied. You have to call it manually:
```js
const stream = require('stream');
const mimicResponse = require('mimic-response');
const responseStream = getHttpResponseStream();
const myStream = new stream.PassThrough({
destroy(error, callback) {
responseStream.destroy();
callback(error);
}
});
myStream.destroy();
```
Please note that `myStream` and `responseStream` never throws. The error is passed to the request instead.
**Note #2:** The `aborted` and `close` events are not proxied. You have to add them manually:
```js
const stream = require('stream');
const mimicResponse = require('mimic-response');
const responseStream = getHttpResponseStream();
const myStream = new stream.PassThrough({
destroy(error, callback) {
responseStream.destroy();
callback(error);
}
});
responseStream.once('aborted', () => {
myStream.destroy();
myStream.emit('aborted');
});
responseStream.once('closed', () => {
myStream.emit('closed');
});
responseStream.pipe(myStream);
```
#### from

@@ -32,0 +81,0 @@

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