Skip to content

Commit

Permalink
fix: handle body with falsy values
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 1, 2021
1 parent 25a6195 commit 6236fc2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const ParsedBodySymbol = Symbol('h3RawBody')
*/
export function useRawBody (req: IncomingMessage, encoding: Encoding = 'utf-8'): Encoding extends false ? Buffer : Promise<string> {
// @ts-ignore
if (req[RawBodySymbol]) {
if (RawBodySymbol in req) {
// @ts-ignore
return Promise.resolve(encoding ? req[RawBodySymbol].toString(encoding) : req[RawBodySymbol])
}

// @ts-ignore
// Workaround for unenv issue https://github.com/unjs/unenv/issues/8
if (req._body) {
if ('_body' in req) {
// @ts-ignore
return Promise.resolve(req._body)
}
Expand Down Expand Up @@ -53,7 +53,7 @@ export function useRawBody (req: IncomingMessage, encoding: Encoding = 'utf-8'):
*/
export async function useBody<T=any> (req: IncomingMessage): Promise<T> {
// @ts-ignore
if (req[ParsedBodySymbol]) {
if (ParsedBodySymbol in req) {
// @ts-ignore
return req[ParsedBodySymbol]
}
Expand Down

0 comments on commit 6236fc2

Please sign in to comment.