pax_global_header00006660000000000000000000000064136224336060014517gustar00rootroot0000000000000052 comment=94bd5a359bad199d801188473e48cb024c6f31ca mimic-response-2.1.0/000077500000000000000000000000001362243360600144515ustar00rootroot00000000000000mimic-response-2.1.0/.editorconfig000066400000000000000000000002571362243360600171320ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 mimic-response-2.1.0/.gitattributes000066400000000000000000000000231362243360600173370ustar00rootroot00000000000000* text=auto eol=lf mimic-response-2.1.0/.github/000077500000000000000000000000001362243360600160115ustar00rootroot00000000000000mimic-response-2.1.0/.github/funding.yml000066400000000000000000000000621362243360600201640ustar00rootroot00000000000000github: sindresorhus tidelift: npm/mimic-response mimic-response-2.1.0/.github/security.md000066400000000000000000000002631362243360600202030ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. mimic-response-2.1.0/.gitignore000066400000000000000000000000271362243360600164400ustar00rootroot00000000000000node_modules yarn.lock mimic-response-2.1.0/.npmrc000066400000000000000000000000231362243360600155640ustar00rootroot00000000000000package-lock=false mimic-response-2.1.0/.travis.yml000066400000000000000000000000651362243360600165630ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' mimic-response-2.1.0/index.d.ts000066400000000000000000000010151362243360600163470ustar00rootroot00000000000000import {IncomingMessage} from 'http'; /** Mimic a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage) Makes `toStream` include the properties from `fromStream`. @param fromStream - The stream to copy the properties from. @param toStream - The stream to copy the properties to. @return The same object as `toStream`. */ declare function mimicResponse( fromStream: IncomingMessage, toStream: T, ): IncomingMessage & T; export = mimicResponse; mimic-response-2.1.0/index.js000066400000000000000000000015421362243360600161200ustar00rootroot00000000000000'use strict'; // We define these manually to ensure they're always copied // even if they would move up the prototype chain // https://nodejs.org/api/http.html#http_class_http_incomingmessage const knownProperties = [ 'aborted', 'complete', 'destroy', 'headers', 'httpVersion', 'httpVersionMinor', 'httpVersionMajor', 'method', 'rawHeaders', 'rawTrailers', 'setTimeout', 'socket', 'statusCode', 'statusMessage', 'trailers', 'url' ]; module.exports = (fromStream, toStream) => { const fromProperties = new Set(Object.keys(fromStream).concat(knownProperties)); for (const property of fromProperties) { // Don't overwrite existing properties. if (property in toStream) { continue; } toStream[property] = typeof fromStream[property] === 'function' ? fromStream[property].bind(fromStream) : fromStream[property]; } return toStream; }; mimic-response-2.1.0/index.test-d.ts000066400000000000000000000010261362243360600173260ustar00rootroot00000000000000import {expectType} from 'tsd'; import http = require('http'); import stream = require('stream'); import mimicResponse = require('.'); class CustomStream extends stream.PassThrough { readonly method = null; } let responseStream!: http.IncomingMessage; const myStream = new stream.PassThrough(); const myCustomStream = new CustomStream(); expectType(mimicResponse(responseStream, myStream)); expectType(mimicResponse(responseStream, myCustomStream)); mimic-response-2.1.0/license000066400000000000000000000021351362243360600160170ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. mimic-response-2.1.0/package.json000066400000000000000000000014151362243360600167400ustar00rootroot00000000000000{ "name": "mimic-response", "version": "2.1.0", "description": "Mimic a Node.js HTTP response stream", "license": "MIT", "repository": "sindresorhus/mimic-response", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.d.ts", "index.js" ], "keywords": [ "mimic", "response", "stream", "http", "https", "request", "get", "core" ], "devDependencies": { "@sindresorhus/tsconfig": "^0.3.0", "@types/node": "^12.0.0", "ava": "^1.1.0", "create-test-server": "^2.4.0", "pify": "^4.0.1", "tsd": "^0.7.3", "xo": "^0.24.0" } } mimic-response-2.1.0/readme.md000066400000000000000000000026451362243360600162370ustar00rootroot00000000000000# mimic-response [![Build Status](https://travis-ci.org/sindresorhus/mimic-response.svg?branch=master)](https://travis-ci.org/sindresorhus/mimic-response) > Mimic a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage) ## Install ``` $ npm install mimic-response ``` ## Usage ```js 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) #### from Type: `Stream` [Node.js HTTP response stream.](https://nodejs.org/api/http.html#http_class_http_incomingmessage) #### to Type: `Stream` Any stream. ## Related - [mimic-fn](https://github.com/sindresorhus/mimic-fn) - Make a function mimic another one - [clone-response](https://github.com/lukechilds/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.
mimic-response-2.1.0/test.js000066400000000000000000000024421362243360600157700ustar00rootroot00000000000000import stream from 'stream'; import http from 'http'; import test from 'ava'; import createTestServer from 'create-test-server'; import pify from 'pify'; import mimicResponse from '.'; let server; test.before(async () => { server = await createTestServer(); server.get('/', (request, response) => { response.send(''); }); }); test('normal', async t => { const response = await pify(http.get, {errorFirst: false})(server.url); response.unicorn = '🦄'; response.getContext = function () { return this; }; const toStream = new stream.PassThrough(); mimicResponse(response, toStream); t.is(toStream.statusCode, 200); t.is(toStream.unicorn, '🦄'); t.is(toStream.getContext(), response.getContext()); }); test('do not overwrite prototype properties', async t => { const response = await pify(http.get, {errorFirst: false})(server.url); response.unicorn = '🦄'; response.getContext = function () { return this; }; const origOn = response.on; response.on = function (name, handler) { return origOn.call(this, name, handler); }; const toStream = new stream.PassThrough(); mimicResponse(response, toStream); t.false(Object.keys(toStream).includes('on')); t.is(toStream.statusCode, 200); t.is(toStream.unicorn, '🦄'); t.is(toStream.getContext(), response.getContext()); }); mimic-response-2.1.0/tsconfig.json000066400000000000000000000001471362243360600171620ustar00rootroot00000000000000{ "extends": "@sindresorhus/tsconfig", "compilerOptions": { "noEmit": true, "allowJs": true } }