Skip to content

Commit

Permalink
feat: support fetch().stream().then()
Browse files Browse the repository at this point in the history
just like `.json()`, etc.
  • Loading branch information
dbushong committed Sep 4, 2018
1 parent 90eea5d commit 19b6c1e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ function callRawBody(res) {
return res.rawBody();
}

function callStream(res) {
return res.stream();
}

function parseErrorBody(rawBody) {
var source = rawBody.toString();
try {
Expand Down Expand Up @@ -125,6 +129,12 @@ var reqProperties = {
return this.then(callRawBody);
},
},

stream: {
value: function stream() {
return this.then(callStream);
},
},
};

function buildFullUrl(options) {
Expand Down Expand Up @@ -283,6 +293,7 @@ function requestFunc(options, resolve, reject) {
function onSocket(socket) {
timing.socket = Date.now() - startTime;

// eslint-disable-next-line no-underscore-dangle
if (socket._connecting || socket.connecting) {
connectTimer = setIOTimeout(onConnectTimedOut, options.connectTimeout);
socket.once('connect', onConnect);
Expand Down

0 comments on commit 19b6c1e

Please sign in to comment.