Browse Source

replace duplexify with patched duplexer2

Closes #135
http2
Vsevolod Strukchinsky 9 years ago
parent
commit
6fa957b53c
  1. 11
      index.js
  2. 2
      package.json

11
index.js

@ -3,10 +3,11 @@
const EventEmitter = require('events').EventEmitter; const EventEmitter = require('events').EventEmitter;
const http = require('http'); const http = require('http');
const https = require('https'); const https = require('https');
const PassThrough = require('stream').PassThrough;
const duplexer2 = require('duplexer2');
const urlLib = require('url'); const urlLib = require('url');
const querystring = require('querystring'); const querystring = require('querystring');
const objectAssign = require('object-assign'); const objectAssign = require('object-assign');
const duplexify = require('duplexify');
const isStream = require('is-stream'); const isStream = require('is-stream');
const getStream = require('get-stream'); const getStream = require('get-stream');
const timedOut = require('timed-out'); const timedOut = require('timed-out');
@ -135,7 +136,9 @@ function asPromise(opts) {
} }
function asStream(opts) { function asStream(opts) {
const proxy = duplexify(); const input = new PassThrough();
const output = new PassThrough();
const proxy = duplexer2(input, output);
if (opts.json) { if (opts.json) {
throw new Error('got can not be used as stream when options.json is used'); throw new Error('got can not be used as stream when options.json is used');
@ -163,7 +166,7 @@ function asStream(opts) {
} }
if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') { if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
proxy.setWritable(req); input.pipe(req);
return; return;
} }
@ -173,7 +176,7 @@ function asStream(opts) {
ee.on('response', res => { ee.on('response', res => {
const statusCode = res.statusCode; const statusCode = res.statusCode;
proxy.setReadable(res); res.pipe(output);
if (statusCode < 200 || statusCode > 299) { if (statusCode < 200 || statusCode > 299) {
proxy.emit('error', new got.HTTPError(statusCode, opts), null, res); proxy.emit('error', new got.HTTPError(statusCode, opts), null, res);

2
package.json

@ -46,7 +46,7 @@
], ],
"dependencies": { "dependencies": {
"create-error-class": "^2.0.0", "create-error-class": "^2.0.0",
"duplexify": "^3.2.0", "duplexer2": "floatdrop/duplexer2#f770b34",
"get-stream": "^1.1.0", "get-stream": "^1.1.0",
"is-plain-obj": "^1.0.0", "is-plain-obj": "^1.0.0",
"is-redirect": "^1.0.0", "is-redirect": "^1.0.0",

Loading…
Cancel
Save