Skip to content

Commit 6df7f21

Browse files
authored
fix(http): always cancel request body in serveFile() (#7041)
1 parent f3d1fac commit 6df7f21

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

http/file_server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ export async function serveFile(
184184
filePath: string,
185185
options?: ServeFileOptions,
186186
): Promise<Response> {
187+
await req.body?.cancel();
188+
187189
if (req.method !== METHOD.Get && req.method !== METHOD.Head) {
188190
return createStandardResponse(STATUS_CODE.MethodNotAllowed);
189191
}
@@ -194,15 +196,13 @@ export async function serveFile(
194196
fileInfo ??= await Deno.stat(filePath);
195197
} catch (error) {
196198
if (error instanceof Deno.errors.NotFound) {
197-
await req.body?.cancel();
198199
return createStandardResponse(STATUS_CODE.NotFound);
199200
} else {
200201
throw error;
201202
}
202203
}
203204

204205
if (fileInfo.isDirectory) {
205-
await req.body?.cancel();
206206
return createStandardResponse(STATUS_CODE.NotFound);
207207
}
208208

0 commit comments

Comments
 (0)