summaryrefslogtreecommitdiff
path: root/ext/http/service.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-04-24 14:03:37 -0400
committerGitHub <noreply@github.com>2024-04-24 14:03:37 -0400
commiteed2598e6cf1db643b4edd07b5eff94c59eb9408 (patch)
tree0320981bba82c78647b9cf335793381400093ad9 /ext/http/service.rs
parentb60822f6e0e3c1f3e360657cfb67c114df2e7032 (diff)
feat(ext/http): Implement request.signal for Deno.serve (#23425)
When the response has been successfully send, we abort the `Request.signal` property to indicate that all resources associated with this transaction may be torn down.
Diffstat (limited to 'ext/http/service.rs')
-rw-r--r--ext/http/service.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/ext/http/service.rs b/ext/http/service.rs
index 932575e37..f38fec4f4 100644
--- a/ext/http/service.rs
+++ b/ext/http/service.rs
@@ -482,12 +482,13 @@ impl HttpRecord {
HttpRecordReady(self)
}
- /// Resolves when response body has finished streaming.
- pub fn response_body_finished(&self) -> impl Future<Output = ()> + '_ {
+ /// Resolves when response body has finished streaming. Returns true if the
+ /// response completed.
+ pub fn response_body_finished(&self) -> impl Future<Output = bool> + '_ {
struct HttpRecordFinished<'a>(&'a HttpRecord);
impl<'a> Future for HttpRecordFinished<'a> {
- type Output = ();
+ type Output = bool;
fn poll(
self: Pin<&mut Self>,
@@ -495,7 +496,10 @@ impl HttpRecord {
) -> Poll<Self::Output> {
let mut mut_self = self.0.self_mut();
if mut_self.response_body_finished {
- return Poll::Ready(());
+ // If we sent the response body and the trailers, this body completed successfully
+ return Poll::Ready(
+ mut_self.response_body.is_complete() && mut_self.trailers.is_none(),
+ );
}
mut_self.response_body_waker = Some(cx.waker().clone());
Poll::Pending