Skip to content

Commit

Permalink
fix: Client.stream writableNeedDrain
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Sep 25, 2020
1 parent 4208071 commit 3cb9234
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ The `handler` parameter is defined as follow:
* `statusCode: Number`
* `headers: Array|Null`
* `socket: Duplex`
* `onHeaders(statusCode, headers, resume): Void`, invoked when statusCode and headers have been received.
* `onHeaders(statusCode, headers, resume): Boolean`, invoked when statusCode and headers have been received.
May be invoked multiple times due to 1xx informational headers.
* `statusCode: Number`
* `headers: Array|Null`, an array of key-value pairs. Keys are not automatically lowercased.
Expand Down
6 changes: 6 additions & 0 deletions lib/client-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class StreamHandler extends AsyncResource {
})

this.res = res

const needDrain = res.writableNeedDrain !== undefined
? res.writableNeedDrain
: res._writableState && res._writableState.needDrain

return needDrain === true
}

onData (chunk) {
Expand Down
4 changes: 3 additions & 1 deletion lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ class Parser extends HTTPParser {
}

try {
request.onHeaders(statusCode, headers, statusCode < 200 ? null : socket[kResume])
if (request.onHeaders(statusCode, headers, statusCode < 200 ? null : socket[kResume]) === false) {
socket[kPause]()
}
} catch (err) {
util.destroy(socket, err)
return 1
Expand Down
2 changes: 1 addition & 1 deletion lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Request {

clearRequestTimeout(this)

this[kHandler].onHeaders(statusCode, headers, resume)
return this[kHandler].onHeaders(statusCode, headers, resume)
}

onBody (chunk, offset, length) {
Expand Down

0 comments on commit 3cb9234

Please sign in to comment.