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)))
})
.map(|r| r?) // flatten Result<Result<...
.flatten()
}
#[cfg(test)]

View file

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

View file

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