diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-11-07 17:12:13 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-07 17:12:13 +0530 |
commit | b9262130fec34137e38c922015c6b671c0fa9396 (patch) | |
tree | f8095a4939560aadbf9bd11d2dcc55f75d4e38a4 /ext/http | |
parent | 742744d4985548a948bc90e78673c0c22d607d8a (diff) |
feat(ext/http): abort signal when request is cancelled (#26761)
Closes https://github.com/denoland/deno/issues/21653
Diffstat (limited to 'ext/http')
-rw-r--r-- | ext/http/00_serve.ts | 8 | ||||
-rw-r--r-- | ext/http/http_next.rs | 8 | ||||
-rw-r--r-- | ext/http/lib.rs | 1 |
3 files changed, 17 insertions, 0 deletions
diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts index 1b70cf212..8cfd7ad53 100644 --- a/ext/http/00_serve.ts +++ b/ext/http/00_serve.ts @@ -11,6 +11,7 @@ import { op_http_cancel, op_http_close, op_http_close_after_finish, + op_http_get_request_cancelled, op_http_get_request_headers, op_http_get_request_method_and_url, op_http_read_request_body, @@ -373,6 +374,13 @@ class InnerRequest { get external() { return this.#external; } + + get isCancelled() { + if (this.#external === null) { + return true; + } + return op_http_get_request_cancelled(this.#external); + } } class CallbackContext { diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs index 56c46de92..326478fe7 100644 --- a/ext/http/http_next.rs +++ b/ext/http/http_next.rs @@ -700,6 +700,14 @@ fn set_response( http.complete(); } +#[op2(fast)] +pub fn op_http_get_request_cancelled(external: *const c_void) -> bool { + let http = + // SAFETY: op is called with external. + unsafe { clone_external!(external, "op_http_get_request_cancelled") }; + http.cancelled() +} + /// Returned promise resolves when body streaming finishes. /// Call [`op_http_close_after_finish`] when done with the external. #[op2(async)] diff --git a/ext/http/lib.rs b/ext/http/lib.rs index 6243804a1..9d71e3ad3 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -113,6 +113,7 @@ deno_core::extension!( http_next::op_http_get_request_header, http_next::op_http_get_request_headers, http_next::op_http_get_request_method_and_url<HTTP>, + http_next::op_http_get_request_cancelled, http_next::op_http_read_request_body, http_next::op_http_serve_on<HTTP>, http_next::op_http_serve<HTTP>, |