Skip to content

Commit

Permalink
fix request stream body
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed May 15, 2023
1 parent 7c5eb0d commit 286a121
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/internal/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ export async function request(
resolve(resp)
})

requestObj.on('error', (e: unknown) => {
reject(e)
})

if (body) {
if (!Buffer.isBuffer(body) && typeof body !== 'string') {
pipeline(body, requestObj, (err) => {
if (err) {
reject(err)
}
if (!body || Buffer.isBuffer(body) || typeof body === 'string') {
requestObj
.on('error', (e: unknown) => {
reject(e)
})
} else {
requestObj.write(body)
}
.end(body)

return
}

requestObj.end()
// pump readable stream
pipeline(body, requestObj, (err) => {
if (err) {
reject(err)
}
})
})
}

0 comments on commit 286a121

Please sign in to comment.