pax_global_header00006660000000000000000000000064131143221250014504gustar00rootroot0000000000000052 comment=44a0267b744d0006b89f69fafc468ed6abbb612b mimic-response-1.0.0/000077500000000000000000000000001311432212500144345ustar00rootroot00000000000000mimic-response-1.0.0/.editorconfig000066400000000000000000000002571311432212500171150ustar00rootroot00000000000000root = 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-1.0.0/.gitattributes000066400000000000000000000000351311432212500173250ustar00rootroot00000000000000* text=auto *.js text eol=lf mimic-response-1.0.0/.gitignore000066400000000000000000000000151311432212500164200ustar00rootroot00000000000000node_modules mimic-response-1.0.0/.travis.yml000066400000000000000000000000631311432212500165440ustar00rootroot00000000000000language: node_js node_js: - '8' - '6' - '4' mimic-response-1.0.0/index.js000066400000000000000000000014521311432212500161030ustar00rootroot00000000000000'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 knownProps = [ 'destroy', 'setTimeout', 'socket', 'headers', 'trailers', 'rawHeaders', 'statusCode', 'httpVersion', 'httpVersionMinor', 'httpVersionMajor', 'rawTrailers', 'statusMessage' ]; module.exports = (fromStream, toStream) => { const toProps = Object.keys(toStream); const fromProps = new Set(Object.keys(fromStream).concat(knownProps)); for (const prop of fromProps) { // Don't overwrite existing properties if (toProps.indexOf(prop) !== -1) { continue; } toStream[prop] = typeof fromStream[prop] === 'function' ? fromStream[prop].bind(fromStream) : fromStream[prop]; } }; mimic-response-1.0.0/license000066400000000000000000000021251311432212500160010ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (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-1.0.0/package.json000066400000000000000000000012131311432212500167170ustar00rootroot00000000000000{ "name": "mimic-response", "version": "1.0.0", "description": "Mimic a Node.js HTTP response stream", "license": "MIT", "repository": "sindresorhus/mimic-response", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "mimic", "response", "stream", "http", "https", "request", "get", "core" ], "devDependencies": { "ava": "*", "create-test-server": "^0.1.0", "pify": "^3.0.0", "xo": "*" } } mimic-response-1.0.0/readme.md000066400000000000000000000020521311432212500162120ustar00rootroot00000000000000# 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 ## License MIT © [Sindre Sorhus](https://sindresorhus.com) mimic-response-1.0.0/test.js000066400000000000000000000012451311432212500157530ustar00rootroot00000000000000import stream from 'stream'; import http from 'http'; import test from 'ava'; import createTestServer from 'create-test-server'; import pify from 'pify'; import m from '.'; let server; test.before(async () => { server = await createTestServer(); server.get('/', (req, res) => { res.send(''); }); }); test(async t => { const response = await pify(http.get, {errorFirst: false})(server.url); response.unicorn = '🦄'; response.getContext = function () { return this; }; const toStream = new stream.PassThrough(); m(response, toStream); t.is(toStream.statusCode, 200); t.is(toStream.unicorn, '🦄'); t.is(toStream.getContext(), response.getContext()); });