From 62305d77d3428b5c714d21b4bbee68cc75b5f787 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Tue, 27 Apr 2021 05:35:02 +0200 Subject: [PATCH] Throw an error when retrying with consumed body Fixes #1694 --- source/as-promise/index.ts | 2 ++ test/post.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/source/as-promise/index.ts b/source/as-promise/index.ts index 2a4291b8f..2d0da2379 100644 --- a/source/as-promise/index.ts +++ b/source/as-promise/index.ts @@ -149,6 +149,8 @@ export default function asPromise(firstRequest: Request): CancelableRequest { message }); }); + +test('formdata retry', withServer, async (t, server, got) => { + server.post('/', echoHeaders); + + const instance = got.extend({ + hooks: { + afterResponse: [ + async (_response, retryWithMergedOptions) => { + return retryWithMergedOptions({ + headers: { + foo: 'bar' + } + }); + } + ] + } + }); + + const form = new FormData(); + form.append('hello', 'world'); + + await t.throwsAsync(instance.post({ + body: form, + headers: form.getHeaders() + }).json<{foo?: string}>(), { + message: 'Cannot retry with consumed body stream' + }); +});