1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

perf(http): avoid clone getting request method and url (#26250)

This commit is contained in:
David Sherret 2024-10-14 23:25:47 -04:00 committed by GitHub
parent 4c9eee3ebe
commit 7f3747f2ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 16 deletions

View file

@ -119,7 +119,7 @@ fn encodings_iter_inner<'s>(
}; };
Some(Ok((encoding, qval))) Some(Ok((encoding, qval)))
}) })
.map(|r| r?) // flatten Result<Result<... .flatten()
} }
#[cfg(test)] #[cfg(test)]

View file

@ -296,7 +296,7 @@ where
let authority: v8::Local<v8::Value> = match request_properties.authority { let authority: v8::Local<v8::Value> = match request_properties.authority {
Some(authority) => v8::String::new_from_utf8( Some(authority) => v8::String::new_from_utf8(
scope, scope,
authority.as_ref(), authority.as_bytes(),
v8::NewStringType::Normal, v8::NewStringType::Normal,
) )
.unwrap() .unwrap()

View file

@ -34,8 +34,8 @@ pub struct HttpConnectionProperties {
pub stream_type: NetworkStreamType, pub stream_type: NetworkStreamType,
} }
pub struct HttpRequestProperties { pub struct HttpRequestProperties<'a> {
pub authority: Option<String>, pub authority: Option<Cow<'a, str>>,
} }
/// Pluggable trait to determine listen, connection and request properties /// Pluggable trait to determine listen, connection and request properties
@ -84,11 +84,11 @@ pub trait HttpPropertyExtractor {
) -> NetworkStream; ) -> NetworkStream;
/// Determines the request properties. /// Determines the request properties.
fn request_properties( fn request_properties<'a>(
connection_properties: &HttpConnectionProperties, connection_properties: &'a HttpConnectionProperties,
uri: &Uri, uri: &'a Uri,
headers: &HeaderMap, headers: &'a HeaderMap,
) -> HttpRequestProperties; ) -> HttpRequestProperties<'a>;
} }
pub struct DefaultHttpPropertyExtractor {} pub struct DefaultHttpPropertyExtractor {}
@ -180,18 +180,17 @@ impl HttpPropertyExtractor for DefaultHttpPropertyExtractor {
} }
} }
fn request_properties( fn request_properties<'a>(
connection_properties: &HttpConnectionProperties, connection_properties: &'a HttpConnectionProperties,
uri: &Uri, uri: &'a Uri,
headers: &HeaderMap, headers: &'a HeaderMap,
) -> HttpRequestProperties { ) -> HttpRequestProperties<'a> {
let authority = req_host( let authority = req_host(
uri, uri,
headers, headers,
connection_properties.stream_type, connection_properties.stream_type,
connection_properties.local_port.unwrap_or_default(), connection_properties.local_port.unwrap_or_default(),
) );
.map(|s| s.into_owned());
HttpRequestProperties { authority } HttpRequestProperties { authority }
} }