Skip to content

Commit d2dd535

Browse files
committed
routes need to explicitly ask to keep connection alive
1 parent a3a57d9 commit d2dd535

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/core/src/v3/apps/http.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ export class HttpReply {
4545
constructor(private response: Parameters<RequestListener>[1]) {}
4646

4747
empty(status?: number) {
48-
if (this.alreadyReplied) {
48+
if (this.hasReplied) {
4949
return;
5050
}
5151

5252
return this.response.writeHead(status ?? 200).end();
5353
}
5454

5555
text(text: string, status?: number, contentType?: string) {
56-
if (this.alreadyReplied) {
56+
if (this.hasReplied) {
5757
return;
5858
}
5959

@@ -63,7 +63,7 @@ export class HttpReply {
6363
}
6464

6565
json(value: any, pretty?: boolean, status?: number) {
66-
if (this.alreadyReplied) {
66+
if (this.hasReplied) {
6767
return;
6868
}
6969

@@ -74,7 +74,7 @@ export class HttpReply {
7474
);
7575
}
7676

77-
private get alreadyReplied() {
77+
get hasReplied() {
7878
return this.response.headersSent;
7979
}
8080
}

packages/core/src/v3/serverOnly/httpServer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface RouteDefinition<
2828
paramsSchema?: TParams;
2929
querySchema?: TQuery;
3030
bodySchema?: TBody;
31+
keepConnectionAlive?: boolean;
3132
handler: RouteHandler<TParams, TQuery, TBody>;
3233
}
3334

@@ -156,7 +157,8 @@ export class HttpServer {
156157
return reply.empty(405);
157158
}
158159

159-
const { handler, paramsSchema, querySchema, bodySchema } = routeDefinition;
160+
const { handler, paramsSchema, querySchema, bodySchema, keepConnectionAlive } =
161+
routeDefinition;
160162

161163
const params = this.parseRouteParams(route, url);
162164
const parsedParams = this.optionalSchema(paramsSchema, params);
@@ -202,6 +204,11 @@ export class HttpServer {
202204
logger.error("Route handler error", { error });
203205
return reply.empty(500);
204206
}
207+
208+
if (keepConnectionAlive) {
209+
// Return early to keep the connection alive
210+
return;
211+
}
205212
} catch (error) {
206213
logger.error("Failed to handle request", { error });
207214
return reply.empty(500);

0 commit comments

Comments
 (0)