From 7c4d40f9edeea9ab8699be866bc1d26efdf0804e Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 15 Apr 2024 18:23:56 +0800 Subject: [PATCH] do not copy request path. (#1022) --- client/src/connection.rs | 2 -- client/src/pool/exclusive.rs | 3 ++- http/src/h1/proto/decode.rs | 10 +++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/client/src/connection.rs b/client/src/connection.rs index b62aaec1..2b8d4336 100644 --- a/client/src/connection.rs +++ b/client/src/connection.rs @@ -43,7 +43,6 @@ impl From for ConnectionShared { #[derive(PartialEq, Eq, Debug, Clone, Hash)] pub enum ConnectionKey { Regular(Authority), - #[cfg(unix)] Unix(AuthorityWithPath), } @@ -71,7 +70,6 @@ impl From<&Uri<'_>> for ConnectionKey { fn from(uri: &Uri<'_>) -> Self { match *uri { Uri::Tcp(uri) | Uri::Tls(uri) => ConnectionKey::Regular(uri.authority().unwrap().clone()), - #[cfg(unix)] Uri::Unix(uri) => ConnectionKey::Unix(AuthorityWithPath { authority: uri.authority().unwrap().clone(), path_and_query: uri.path_and_query().unwrap().clone(), diff --git a/client/src/pool/exclusive.rs b/client/src/pool/exclusive.rs index 5e743321..b6f258c4 100644 --- a/client/src/pool/exclusive.rs +++ b/client/src/pool/exclusive.rs @@ -34,7 +34,8 @@ where } } - // acquire a connection from pool. if a new connection needs to be made + // acquire a connection from pool. if a new connection needs to be made a spawner type + // would be returned. pub(crate) async fn acquire(&self, key: impl Into) -> AcquireOutput<'_, K, C> { let key = key.into(); diff --git a/http/src/h1/proto/decode.rs b/http/src/h1/proto/decode.rs index c7f2621f..112d9524 100644 --- a/http/src/h1/proto/decode.rs +++ b/http/src/h1/proto/decode.rs @@ -34,8 +34,6 @@ impl Context<'_, D, MAX_HEADERS> { let method = Method::from_bytes(req.method.unwrap().as_bytes())?; - let uri = req.path.unwrap().parse::()?; - // default body decoder from method. let mut decoder = match method { // set method to context so it can pass method to response. @@ -62,12 +60,18 @@ impl Context<'_, D, MAX_HEADERS> { // record indices of headers from bytes buffer. let mut header_idx = uninit::uninit_array::<_, MAX_HEADERS>(); let header_idx_slice = HeaderIndex::record(&mut header_idx, buf, req.headers); - let headers_len = req.headers.len(); + // record indices of request path from buffer. + let path = req.path.unwrap(); + let path_head = path.as_ptr() as usize - buf.as_ptr() as usize; + let path_len = path.len(); + // split the headers from buffer. let slice = buf.split_to(len).freeze(); + let uri = Uri::from_maybe_shared(slice.slice(path_head..path_head + path_len))?; + // pop a cached headermap or construct a new one. let mut headers = self.take_headers(); headers.reserve(headers_len);