Skip to content

Commit

Permalink
convert body to string unless octet-stream (#1121)
Browse files Browse the repository at this point in the history
* convert body to string unless octet-stream

* lockfile
  • Loading branch information
Rich Harris authored Apr 19, 2021
1 parent 9c33613 commit d3cb858
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-news-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-netlify': patch
---

Convert body to string, unless type is octet-stream
9 changes: 8 additions & 1 deletion packages/adapter-netlify/files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ export async function handler(event) {
});
}

const rawBody =
headers['content-type'] === 'application/octet-stream'
? new TextEncoder('base64').encode(body).buffer
: isBase64Encoded
? Buffer.from(body, 'base64').toString()
: body;

const rendered = await render({
method: httpMethod,
headers,
path,
query,
rawBody: isBase64Encoded ? new TextEncoder('base64').encode(body).buffer : body
rawBody
});

if (rendered) {
Expand Down
11 changes: 8 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d3cb858

Please sign in to comment.