From 1297c9a8f379d89691522c5cc0c6071c479e95a1 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Sat, 23 Dec 2023 08:58:20 -0700 Subject: chore(ext/node): use BufView natively in http2 (#21688) Node HTTP/2 was using the default h2 `Bytes` datatype when we can be making using of `BufView` like we do in `Deno.serve`. `fetch` and `Deno.serverHttp` can't make use of `BufView` because they are using `reqwest` which is stuck on hyper 0.x at this time. --- ext/node/ops/http2.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'ext/node') diff --git a/ext/node/ops/http2.rs b/ext/node/ops/http2.rs index 676ef7e6e..353a42e8b 100644 --- a/ext/node/ops/http2.rs +++ b/ext/node/ops/http2.rs @@ -12,6 +12,7 @@ use deno_core::futures::future::poll_fn; use deno_core::op2; use deno_core::serde::Serialize; use deno_core::AsyncRefCell; +use deno_core::BufView; use deno_core::ByteString; use deno_core::CancelFuture; use deno_core::CancelHandle; @@ -34,7 +35,7 @@ use reqwest::header::HeaderValue; use url::Url; pub struct Http2Client { - pub client: AsyncRefCell>, + pub client: AsyncRefCell>, pub url: Url, } @@ -46,7 +47,7 @@ impl Resource for Http2Client { #[derive(Debug)] pub struct Http2ClientConn { - pub conn: AsyncRefCell>, + pub conn: AsyncRefCell>, cancel_handle: CancelHandle, } @@ -63,7 +64,7 @@ impl Resource for Http2ClientConn { #[derive(Debug)] pub struct Http2ClientStream { pub response: AsyncRefCell, - pub stream: AsyncRefCell>, + pub stream: AsyncRefCell>, } impl Resource for Http2ClientStream { @@ -89,7 +90,7 @@ impl Resource for Http2ClientResponseBody { #[derive(Debug)] pub struct Http2ServerConnection { - pub conn: AsyncRefCell>, + pub conn: AsyncRefCell>, } impl Resource for Http2ServerConnection { @@ -99,7 +100,7 @@ impl Resource for Http2ServerConnection { } pub struct Http2ServerSendResponse { - pub send_response: AsyncRefCell>, + pub send_response: AsyncRefCell>, } impl Resource for Http2ServerSendResponse { @@ -123,7 +124,8 @@ pub async fn op_http2_connect( let url = Url::parse(&url)?; - let (client, conn) = h2::client::handshake(network_stream).await?; + let (client, conn) = + h2::client::Builder::new().handshake(network_stream).await?; let mut state = state.borrow_mut(); let client_rid = state.resource_table.add(Http2Client { client: AsyncRefCell::new(client), @@ -145,7 +147,7 @@ pub async fn op_http2_listen( let stream = take_network_stream_resource(&mut state.borrow_mut().resource_table, rid)?; - let conn = h2::server::handshake(stream).await?; + let conn = h2::server::Builder::new().handshake(stream).await?; Ok( state .borrow_mut() @@ -349,7 +351,7 @@ pub async fn op_http2_client_send_data( let mut stream = RcRef::map(&resource, |r| &r.stream).borrow_mut().await; // TODO(bartlomieju): handle end of stream - stream.send_data(bytes::Bytes::from(data), false)?; + stream.send_data(data.to_vec().into(), false)?; Ok(()) } @@ -365,7 +367,7 @@ pub async fn op_http2_client_end_stream( let mut stream = RcRef::map(&resource, |r| &r.stream).borrow_mut().await; // TODO(bartlomieju): handle end of stream - stream.send_data(bytes::Bytes::from(vec![]), true)?; + stream.send_data(BufView::empty(), true)?; Ok(()) } -- cgit v1.2.3