diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-05-18 20:10:25 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 20:10:25 -0600 |
commit | 2b92efa64501320955979a92de39c70b6734f835 (patch) | |
tree | 699473092934d5f221a440c235e9858cce17d5a3 /ext/http/slab.rs | |
parent | 5b0752234993ee69e47c32db478d2a296f73f396 (diff) |
feat(ext/http): Add support for trailers w/internal API (HTTP/2 only) (#19182)
Necessary for #3326.
Requested in #10214 as well.
Diffstat (limited to 'ext/http/slab.rs')
-rw-r--r-- | ext/http/slab.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ext/http/slab.rs b/ext/http/slab.rs index 24554d689..93a56e9ff 100644 --- a/ext/http/slab.rs +++ b/ext/http/slab.rs @@ -4,6 +4,7 @@ use crate::response_body::CompletionHandle; use crate::response_body::ResponseBytes; use deno_core::error::AnyError; use http::request::Parts; +use http::HeaderMap; use hyper1::body::Incoming; use hyper1::upgrade::OnUpgrade; @@ -11,6 +12,7 @@ use slab::Slab; use std::cell::RefCell; use std::cell::RefMut; use std::ptr::NonNull; +use std::rc::Rc; pub type Request = hyper1::Request<Incoming>; pub type Response = hyper1::Response<ResponseBytes>; @@ -23,6 +25,7 @@ pub struct HttpSlabRecord { // The response may get taken before we tear this down response: Option<Response>, promise: CompletionHandle, + trailers: Rc<RefCell<Option<HeaderMap>>>, been_dropped: bool, #[cfg(feature = "__zombie_http_tracking")] alive: bool, @@ -81,11 +84,14 @@ fn slab_insert_raw( ) -> SlabId { let index = SLAB.with(|slab| { let mut slab = slab.borrow_mut(); + let body = ResponseBytes::default(); + let trailers = body.trailers(); slab.insert(HttpSlabRecord { request_info, request_parts, request_body, - response: Some(Response::new(ResponseBytes::default())), + response: Some(Response::new(body)), + trailers, been_dropped: false, promise: CompletionHandle::default(), #[cfg(feature = "__zombie_http_tracking")] @@ -182,6 +188,11 @@ impl SlabEntry { self.self_mut().response.as_mut().unwrap() } + /// Get a mutable reference to the trailers. + pub fn trailers(&mut self) -> &RefCell<Option<HeaderMap>> { + &self.self_mut().trailers + } + /// Take the response. pub fn take_response(&mut self) -> Response { self.self_mut().response.take().unwrap() |