summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Ogórek <kamil.ogorek@gmail.com>2023-06-03 20:15:53 +0200
committerGitHub <noreply@github.com>2023-06-03 12:15:53 -0600
commit7d0853d15863b2fb61bcf5927139cfdd3d869d73 (patch)
treed1f27d40d18a85c62361b0735991f81a7918d9f0
parent260d2ec3a1d6c49892fd339b6a8171596a72b8ad (diff)
perf(ext/http): Migrate op_http_get_request_method_and_url to v8::Array (#19355)
Tackles 3rd item from https://github.com/denoland/deno/issues/19330 list. Before: 113.9k After: 114.3k
-rw-r--r--ext/http/http_next.rs55
1 files changed, 45 insertions, 10 deletions
diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs
index 289c38705..14b5457e5 100644
--- a/ext/http/http_next.rs
+++ b/ext/http/http_next.rs
@@ -215,10 +215,11 @@ pub fn op_http_set_promise_complete(slab_id: SlabId, status: u16) {
http.complete();
}
-#[op]
-pub fn op_http_get_request_method_and_url<HTTP>(
+#[op(v8)]
+pub fn op_http_get_request_method_and_url<'scope, HTTP>(
+ scope: &mut v8::HandleScope<'scope>,
slab_id: SlabId,
-) -> (String, Option<String>, String, String, Option<u16>)
+) -> serde_v8::Value<'scope>
where
HTTP: HttpPropertyExtractor,
{
@@ -231,20 +232,54 @@ where
&request_parts.headers,
);
+ let method: v8::Local<v8::Value> = v8::String::new_from_utf8(
+ scope,
+ request_parts.method.as_str().as_bytes(),
+ v8::NewStringType::Normal,
+ )
+ .unwrap()
+ .into();
+
+ let authority: v8::Local<v8::Value> = match request_properties.authority {
+ Some(authority) => v8::String::new_from_utf8(
+ scope,
+ authority.as_ref(),
+ v8::NewStringType::Normal,
+ )
+ .unwrap()
+ .into(),
+ None => v8::undefined(scope).into(),
+ };
+
// Only extract the path part - we handle authority elsewhere
let path = match &request_parts.uri.path_and_query() {
Some(path_and_query) => path_and_query.to_string(),
None => "".to_owned(),
};
- // TODO(mmastrac): Passing method can be optimized
- (
- request_parts.method.as_str().to_owned(),
- request_properties.authority,
- path,
- String::from(request_info.peer_address.as_ref()),
- request_info.peer_port,
+ let path: v8::Local<v8::Value> =
+ v8::String::new_from_utf8(scope, path.as_ref(), v8::NewStringType::Normal)
+ .unwrap()
+ .into();
+
+ let peer_address: v8::Local<v8::Value> = v8::String::new_from_utf8(
+ scope,
+ request_info.peer_address.as_bytes(),
+ v8::NewStringType::Normal,
)
+ .unwrap()
+ .into();
+
+ let port: v8::Local<v8::Value> = match request_info.peer_port {
+ Some(port) => v8::Integer::new(scope, port.into()).into(),
+ None => v8::undefined(scope).into(),
+ };
+
+ let vec = [method, authority, path, peer_address, port];
+ let array = v8::Array::new_with_elements(scope, vec.as_slice());
+ let array_value: v8::Local<v8::Value> = array.into();
+
+ array_value.into()
}
#[op]