summaryrefslogtreecommitdiff
path: root/ext/http
diff options
context:
space:
mode:
Diffstat (limited to 'ext/http')
-rw-r--r--ext/http/00_serve.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts
index a58d19d76..8ed1a1d04 100644
--- a/ext/http/00_serve.ts
+++ b/ext/http/00_serve.ts
@@ -436,6 +436,11 @@ function fastSyncResponseOrStream(
const stream = respBody.streamOrStatic;
const body = stream.body;
+ if (body !== undefined) {
+ // We ensure the response has not been consumed yet in the caller of this
+ // function.
+ stream.consumed = true;
+ }
if (TypedArrayPrototypeGetSymbolToStringTag(body) === "Uint8Array") {
innerRequest?.close();
@@ -505,6 +510,12 @@ function mapToCallback(context, callback, onError) {
"Return value from serve handler must be a response or a promise resolving to a response",
);
}
+
+ if (response.bodyUsed) {
+ throw TypeError(
+ "The body of the Response returned from the serve handler has already been consumed.",
+ );
+ }
} catch (error) {
try {
response = await onError(error);