Skip to content

fix(http-client): replay the request body on redirects without throwing - #4136

Open
SulimanAbdulrazzaq wants to merge 1 commit into
apify:masterfrom
SulimanAbdulrazzaq:fix/redirect-body-duplex
Open

SulimanAbdulrazzaq wants to merge 1 commit into
apify:masterfrom
SulimanAbdulrazzaq:fix/redirect-body-duplex

Conversation

@SulimanAbdulrazzaq

Copy link
Copy Markdown

buildRedirectRequest() passed the cloned request body, a ReadableStream, to new Request() without duplex: 'half', which Node rejects. So every redirect that keeps the body (307/308, and 301/302 for methods other than POST) made sendRequest() throw TypeError: RequestInit: duplex option is required when sending a body. instead of following it. HttpCrawler requests with a payload failed the same way, because the crawler sends the payload as a stream.

The redirected request now sets duplex: 'half', the same option HttpCrawler already sets on its initial request. The replay itself was already correct, because initialRequest is cloned before the first send.

Closes #4133

`buildRedirectRequest()` passes the cloned body stream to `new Request()`
without `duplex: 'half'`, which Node rejects. Every redirect that keeps the
body (307/308, and 301/302 for methods other than POST) made `sendRequest()`
throw a `TypeError` instead of following the redirect.

Closes apify#4133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BaseHttpClient.sendRequest() throws on any redirect that preserves the request body

2 participants