source: node_modules/mimic-response/readme.md@ 81bc7da

finki-main main
Last change on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1# mimic-response [![Build Status](https://travis-ci.com/sindresorhus/mimic-response.svg?branch=master)](https://travis-ci.com/sindresorhus/mimic-response)
2
3> Mimic a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
4
5## Install
6
7```
8$ npm install mimic-response
9```
10
11## Usage
12
13```js
14const stream = require('stream');
15const mimicResponse = require('mimic-response');
16
17const responseStream = getHttpResponseStream();
18const myStream = new stream.PassThrough();
19
20mimicResponse(responseStream, myStream);
21
22console.log(myStream.statusCode);
23//=> 200
24```
25
26## API
27
28### mimicResponse(from, to)
29
30**Note #1:** The `from.destroy(error)` function is not proxied. You have to call it manually:
31
32```js
33const stream = require('stream');
34const mimicResponse = require('mimic-response');
35
36const responseStream = getHttpResponseStream();
37
38const myStream = new stream.PassThrough({
39 destroy(error, callback) {
40 responseStream.destroy();
41
42 callback(error);
43 }
44});
45
46myStream.destroy();
47```
48
49Please note that `myStream` and `responseStream` never throws. The error is passed to the request instead.
50
51#### from
52
53Type: `Stream`
54
55[Node.js HTTP response stream.](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
56
57#### to
58
59Type: `Stream`
60
61Any stream.
62
63## Related
64
65- [mimic-fn](https://github.com/sindresorhus/mimic-fn) - Make a function mimic another one
66- [clone-response](https://github.com/lukechilds/clone-response) - Clone a Node.js response stream
67
68---
69
70<div align="center">
71 <b>
72 <a href="https://tidelift.com/subscription/pkg/npm-mimic-response?utm_source=npm-mimic-response&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
73 </b>
74 <br>
75 <sub>
76 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
77 </sub>
78</div>
Note: See TracBrowser for help on using the repository browser.