Skip to content

Commit

Permalink
fixup! ensure request.body is drained
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Feb 28, 2024
1 parent c5a89c4 commit abe0d45
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ const drainBody: Middleware = async (request, env, _ctx, middlewareCtx) => {
try {
return await middlewareCtx.next(request, env);
} finally {
if (request.body !== null && !request.bodyUsed) {
const reader = request.body.getReader();
while (!(await reader.read()).done) {}
try {
if (request.body !== null && !request.bodyUsed) {
const reader = request.body.getReader();
while (!(await reader.read()).done) {}
}
} catch (e) {
console.error("Failed to drain the unused request body.", e);
}
}
};
Expand Down

0 comments on commit abe0d45

Please sign in to comment.