Skip to content
Mimic a Node.js HTTP response stream
JavaScript TypeScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Tidelift tasks Sep 10, 2019
.editorconfig Init Jun 2, 2017
.gitattributes Require Node.js 6 Jul 11, 2018
.gitignore Require Node.js 6 Jul 11, 2018
.npmrc Require Node.js 6 Jul 11, 2018
.travis.yml Require Node.js 10 May 13, 2020
index.d.ts Require Node.js 10 May 13, 2020
index.js Proxy events (#7) May 14, 2020
index.test-d.ts Require Node.js 10 May 13, 2020
license
package.json
readme.md Proxy events (#7) May 14, 2020
test.js

readme.md

mimic-response Build Status

Mimic a Node.js HTTP response stream

Install

$ npm install mimic-response

Usage

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

const responseStream = getHttpResponseStream();
const myStream = new stream.PassThrough();

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:

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.

from

Type: Stream

Node.js HTTP response stream.

to

Type: Stream

Any stream.

Related


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.
You can’t perform that action at this time.