Skip to content

Commit

Permalink
fix: check if stream is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
DTrombett committed Nov 21, 2024
1 parent e5b5894 commit be844b6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/handler/redirect-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ class RedirectHandler {
// In case of HTTP 301 or 302 with POST, change the method to GET
if ((statusCode === 301 || statusCode === 302) && this.opts.method === 'POST') {
this.opts.method = 'GET'
util.destroy(this.opts.body.on?.('error', () => {}))
if (util.isStream(this.opts.body)) util.destroy(this.opts.body.on('error', () => {}))
this.opts.body = null
}

// https://tools.ietf.org/html/rfc7231#section-6.4.4
// In case of HTTP 303, always replace method to be either HEAD or GET
if (statusCode === 303 && this.opts.method !== 'HEAD') {
this.opts.method = 'GET'
util.destroy(this.opts.body.on?.('error', () => {}))
if (util.isStream(this.opts.body)) util.destroy(this.opts.body.on('error', () => {}))
this.opts.body = null
}
}
Expand Down

0 comments on commit be844b6

Please sign in to comment.