Skip to content

Commit

Permalink
fix: destroy request body when we are aborting it midway though r… (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Apr 7, 2020
1 parent dae0483 commit 1f7506d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,27 @@ const ndjson = async function * (source) {

const streamToAsyncIterator = function (source) {
if (isAsyncIterator(source)) {
// Workaround for https://github.com/node-fetch/node-fetch/issues/766
if (source.writable && source.readable) {
const iter = source[Symbol.asyncIterator]()

const wrapper = {
next: iter.next.bind(iter),
return: () => {
if (source.writableEnded) {
source.destroy()
}

return iter.return()
},
[Symbol.asyncIterator]: () => {
return wrapper
}
}

return wrapper
}

return source
}

Expand Down

0 comments on commit 1f7506d

Please sign in to comment.