Socket
Socket
Sign inDemoInstall

mimic-response

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

mimic-response

Mimic a Node.js HTTP response stream


Version published
Maintainers
1
Weekly downloads
27,700,033
decreased by-6.52%

Weekly downloads

Package description

What is mimic-response?

The mimic-response npm package is designed to copy properties from one response-like object to another. This is particularly useful when you are working with streams and you want to retain the original response properties after modifying or replacing the response stream.

What are mimic-response's main functionalities?

Copying response properties

This feature allows you to copy properties from an HTTP response object to another stream. In this code sample, an HTTP GET request is made, and the response is piped through a new PassThrough stream, but before that, all properties of the original response are copied to the new stream using mimicResponse.

const http = require('http');
const mimicResponse = require('mimic-response');

http.get('http://example.com', (res) => {
  const customResponse = new stream.PassThrough();
  mimicResponse(res, customResponse);
  res.pipe(customResponse);
});

Other packages similar to mimic-response

Readme

Source

mimic-response

Mimic a Node.js HTTP response stream

Install

$ npm install mimic-response

Usage

import {PassThrough as PassThroughStream} from 'node:stream';
import mimicResponse from 'mimic-response';

const responseStream = getHttpResponseStream();
const myStream = new PassThroughStream();

mimicResponse(responseStream, myStream);

console.log(myStream.statusCode);
//=> 200

API

mimicResponse(from, to)

Note #1: The from.destroy(error) function is not proxied. You have to call it manually:

import {PassThrough as PassThroughStream} from 'node:stream';
import mimicResponse from 'mimic-response';

const responseStream = getHttpResponseStream();

const myStream = new PassThroughStream({
	destroy(error, callback) {
		responseStream.destroy();

		callback(error);
	}
});

myStream.destroy();

Please note that myStream and responseStream never throw. The error is passed to the request instead.

from

Type: Stream

Node.js HTTP response stream.

to

Type: Stream

Any stream.

  • mimic-fn - Make a function mimic another one
  • clone-response - Clone a Node.js response stream

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 11 Aug 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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