Skip to content

Commit

Permalink
feat: allow pausing from onHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Oct 11, 2020
1 parent b1ba471 commit 4ae8b9d
Show file tree
Hide file tree
Showing 3 changed files with 5 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
4 changes: 3 additions & 1 deletion lib/core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,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 4ae8b9d

Please sign in to comment.