Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Require Node.js 10
Node.js 8 is out of LTS in December.
- Loading branch information
1 parent
e98f2a1
commit 633651f
Showing
24 changed files
with
164 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import {PassThrough as PassThroughStream, Duplex as DuplexStream} from 'stream'; | ||
import stream = require('stream'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sindresorhus
Author
Owner
|
||
import {IncomingMessage} from 'http'; | ||
import duplexer3 = require('duplexer3'); | ||
import requestAsEventEmitter from './request-as-event-emitter'; | ||
|
@@ -50,10 +51,6 @@ export default function asStream(options: NormalizedOptions): ProxyStream { | |
const {statusCode, isFromCache} = response; | ||
proxy.isFromCache = isFromCache; | ||
|
||
response.on('error', error => { | ||
emitError(new ReadError(error, options)); | ||
}); | ||
|
||
if (options.throwHttpErrors && statusCode !== 304 && (statusCode < 200 || statusCode > 299)) { | ||
emitError(new HTTPError(response, options)); | ||
return; | ||
|
@@ -63,12 +60,19 @@ export default function asStream(options: NormalizedOptions): ProxyStream { | |
const read = proxy._read.bind(proxy); | ||
proxy._read = (...args) => { | ||
isFinished = true; | ||
|
||
return read(...args); | ||
}; | ||
} | ||
|
||
response.pipe(output); | ||
stream.pipeline( | ||
response, | ||
output, | ||
error => { | ||
if (error) { | ||
emitError(new ReadError(error, options)); | ||
} | ||
} | ||
); | ||
|
||
for (const destination of piped) { | ||
if (destination.headersSent) { | ||
|
@@ -90,15 +94,19 @@ export default function asStream(options: NormalizedOptions): ProxyStream { | |
proxy.emit('response', response); | ||
}); | ||
|
||
[ | ||
const events = [ | ||
'error', | ||
'request', | ||
'redirect', | ||
'uploadProgress', | ||
'downloadProgress' | ||
].forEach(event => emitter.on(event, (...args) => { | ||
proxy.emit(event, ...args); | ||
})); | ||
]; | ||
|
||
for (const event of events) { | ||
emitter.on(event, (...args) => { | ||
proxy.emit(event, ...args); | ||
}); | ||
} | ||
|
||
const pipe = proxy.pipe.bind(proxy); | ||
const unpipe = proxy.unpipe.bind(proxy); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import {URL} from 'url'; | ||
import test from 'ava'; | ||
import delay = require('delay'); | ||
import got from '../source'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Why not