Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Apr 30, 2024
1 parent ed9d992 commit c1585b6
Showing 1 changed file with 8 additions and 3 deletions.
Expand Up @@ -52,7 +52,7 @@ function incomingMessageToBodyStream(
return stream;
}

const bodyMethods = ['POST', 'PUT', 'PATCH'];
const bodyMethods = new Set(['POST', 'PUT', 'PATCH']);
/**
* Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
*/
Expand All @@ -79,10 +79,15 @@ export function incomingMessageToRequest(
duplex: 'half',
};

if (req.method && bodyMethods.includes(req.method)) {
if (req.method && bodyMethods.has(req.method)) {
if (!('body' in req)) {
init.body = incomingMessageToBodyStream(req, opts);
} else if (typeof req.body === 'string') {
} else if (
typeof req.body === 'string' ||
req.body instanceof Uint8Array ||
req.body instanceof Buffer ||
req.body instanceof ReadableStream
) {
init.body = req.body;
} else if (req.body !== undefined) {
init.body = JSON.stringify(req.body);
Expand Down

0 comments on commit c1585b6

Please sign in to comment.