diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2020-12-22 14:14:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-22 14:14:23 +0100 |
commit | ddda669a02fa394627dda2ac3d7ea0ed8830b920 (patch) | |
tree | 40c1589bd9b8d54b1f0cc15e07e1012cface7e01 /cli/tests/unit/fetch_test.ts | |
parent | 097c3379ba8a5dce5d9a73771693205d8178792d (diff) |
fix: implement ReadableStream fetch body handling (#8855)
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 6f90a1847..359a24e95 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1013,3 +1013,43 @@ MNf4EgWfK+tZMnuqfpfO9740KzfcVoMNo4QJD4yn5YxroUOO/Azi client.close(); }, ); + +unitTest( + { + perms: { net: true }, + }, + async function fetchPostBodyReadableStream(): Promise<void> { + const addr = "127.0.0.1:4502"; + const buf = bufferServer(addr); + const stream = new TransformStream(); + const writer = stream.writable.getWriter(); + await writer.write(new TextEncoder().encode("hello ")); + await writer.write(new TextEncoder().encode("world")); + await writer.close(); + const response = await fetch(`http://${addr}/blah`, { + method: "POST", + headers: [ + ["Hello", "World"], + ["Foo", "Bar"], + ], + body: stream.readable, + }); + await response.arrayBuffer(); + assertEquals(response.status, 404); + assertEquals(response.headers.get("Content-Length"), "2"); + + const actual = new TextDecoder().decode(buf.bytes()); + const expected = [ + "POST /blah HTTP/1.1\r\n", + "hello: World\r\n", + "foo: Bar\r\n", + "accept: */*\r\n", + `user-agent: Deno/${Deno.version.deno}\r\n`, + "accept-encoding: gzip, br\r\n", + `host: ${addr}\r\n`, + `content-length: 11\r\n\r\n`, + "hello world", + ].join(""); + assertEquals(actual, expected); + }, +); |