summaryrefslogtreecommitdiff
path: root/packages/integrations
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-07-26 10:31:54 -0400
committerGravatar GitHub <noreply@github.com> 2022-07-26 10:31:54 -0400
commit8c3de73ebfae60aa0204ef748fd2c124ee64867a (patch)
tree9c62632c0ac72082c0ca85deea039159655edf75 /packages/integrations
parent80e2e59036b3e13b4ff3ce13e0c3f78b3d08effa (diff)
downloadastro-8c3de73ebfae60aa0204ef748fd2c124ee64867a.tar.gz
astro-8c3de73ebfae60aa0204ef748fd2c124ee64867a.tar.zst
astro-8c3de73ebfae60aa0204ef748fd2c124ee64867a.zip
Fixes binary data request bodies in the Node adapter (#4055)
* Fixes binary data request bodies in the Node adapter * Fix type
Diffstat (limited to 'packages/integrations')
-rw-r--r--packages/integrations/node/test/api-route.test.js16
-rw-r--r--packages/integrations/node/test/fixtures/api-route/src/pages/binary.ts11
2 files changed, 27 insertions, 0 deletions
diff --git a/packages/integrations/node/test/api-route.test.js b/packages/integrations/node/test/api-route.test.js
index 034b53c07..cd074ef27 100644
--- a/packages/integrations/node/test/api-route.test.js
+++ b/packages/integrations/node/test/api-route.test.js
@@ -31,4 +31,20 @@ describe('API routes', () => {
expect(json.length).to.equal(1);
expect(json[0].name).to.equal('Broccoli Soup');
});
+
+ it('Can get binary data', async () => {
+ const { handler } = await import('./fixtures/api-route/dist/server/entry.mjs');
+
+ let { req, res, done } = createRequestAndResponse({
+ method: 'POST',
+ url: '/binary',
+ });
+
+ handler(req, res);
+ req.send(Buffer.from(new Uint8Array([1, 2, 3, 4, 5])));
+
+ let [out] = await done;
+ let arr = Array.from(new Uint8Array(out.buffer));
+ expect(arr).to.deep.equal([5, 4, 3, 2, 1]);
+ });
});
diff --git a/packages/integrations/node/test/fixtures/api-route/src/pages/binary.ts b/packages/integrations/node/test/fixtures/api-route/src/pages/binary.ts
new file mode 100644
index 000000000..6b50bc341
--- /dev/null
+++ b/packages/integrations/node/test/fixtures/api-route/src/pages/binary.ts
@@ -0,0 +1,11 @@
+
+export async function post({ request }: { request: Request }) {
+ let body = await request.arrayBuffer();
+ let data = new Uint8Array(body);
+ let r = data.reverse();
+ return new Response(r, {
+ headers: {
+ 'Content-Type': 'application/octet-stream'
+ }
+ });
+}