Skip to content

Commit a0b6f4d

Browse files
committed
refactor(uWebSockets): corked responses
1 parent c7ff568 commit a0b6f4d

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/use/uWebSockets.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ export function createHandler<Context extends OperationContext = undefined>(
7676
context: { res },
7777
});
7878
if (!aborted) {
79-
res.writeStatus(`${init.status} ${init.statusText}`);
80-
for (const [key, val] of Object.entries(init.headers || {})) {
81-
res.writeHeader(key, val);
82-
}
83-
if (body) {
84-
res.end(body);
85-
} else {
86-
res.endWithoutBody();
87-
}
79+
res.cork(() => {
80+
res.writeStatus(`${init.status} ${init.statusText}`);
81+
for (const [key, val] of Object.entries(init.headers || {})) {
82+
res.writeHeader(key, val);
83+
}
84+
if (body) {
85+
res.end(body);
86+
} else {
87+
res.endWithoutBody();
88+
}
89+
});
8890
}
8991
} catch (err) {
9092
// The handler shouldnt throw errors.
@@ -95,7 +97,9 @@ export function createHandler<Context extends OperationContext = undefined>(
9597
err,
9698
);
9799
if (!aborted) {
98-
res.writeStatus('500 Internal Server Error').endWithoutBody();
100+
res.cork(() => {
101+
res.writeStatus('500 Internal Server Error').endWithoutBody();
102+
});
99103
}
100104
}
101105
};

0 commit comments

Comments
 (0)