Skip to content

Commit

Permalink
fix(readRawBody): resolve cached promise before normalizing buffer
Browse files Browse the repository at this point in the history
closes #369
  • Loading branch information
pi0 committed May 5, 2023
1 parent a6ccd2c commit 2e472e8
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/utils/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ export function readRawBody<E extends Encoding = "utf8">(
(event.node.req as any)[RawBodySymbol] ||
(event.node.req as any).body; /* unjs/unenv #8 */
if (_rawBody) {
const promise = Promise.resolve(
Buffer.isBuffer(_rawBody) ? _rawBody : Buffer.from(_rawBody)
);
const promise = Promise.resolve(_rawBody)
.then(_resolved => Buffer.isBuffer(_resolved) ? _resolved : Buffer.from(_resolved))
return encoding
? promise.then((buff) => buff.toString(encoding))
: (promise as Promise<any>);
Expand Down

0 comments on commit 2e472e8

Please sign in to comment.