summaryrefslogtreecommitdiff
path: root/ext/http/lib.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-09 10:56:19 -0400
committerGitHub <noreply@github.com>2023-03-09 14:56:19 +0000
commit8f207c0f3f3a43d77e0c88cfdc840b4b742b9708 (patch)
treea8699bca5ffffff03a9d72f1bed9208a349338ba /ext/http/lib.rs
parent99da8a69e7260b72e55d7214ec96f6ac5e759f35 (diff)
refactor: Split extension registration for runtime and snapshotting (#18095)
This commit splits "<ext_name>::init" functions into "init_ops" and "init_ops_and_esm". That way we don't have to construct list of ESM sources on each startup if we're running with a snapshot. In a follow up commit "deno_core" will be changed to not have a split between "extensions" and "extensions_with_js" - it will be embedders' responsibility to pass appropriately configured extensions. Prerequisite for https://github.com/denoland/deno/pull/18080
Diffstat (limited to 'ext/http/lib.rs')
-rw-r--r--ext/http/lib.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index 14a93ede9..8fd7015aa 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -30,6 +30,7 @@ use deno_core::CancelFuture;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::Extension;
+use deno_core::ExtensionBuilder;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::Resource;
@@ -77,13 +78,15 @@ use crate::reader_stream::ShutdownHandle;
pub mod compressible;
mod reader_stream;
-pub fn init() -> Extension {
+fn ext() -> ExtensionBuilder {
Extension::builder_with_deps(
env!("CARGO_PKG_NAME"),
&["deno_web", "deno_net", "deno_fetch", "deno_websocket"],
)
- .esm(include_js_files!("01_http.js",))
- .ops(vec![
+}
+
+fn ops(ext: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
+ ext.ops(vec![
op_http_accept::decl(),
op_http_write_headers::decl(),
op_http_headers::decl(),
@@ -93,7 +96,16 @@ pub fn init() -> Extension {
op_http_websocket_accept_header::decl(),
op_http_upgrade_websocket::decl(),
])
- .build()
+}
+
+pub fn init_ops_and_esm() -> Extension {
+ ops(&mut ext())
+ .esm(include_js_files!("01_http.js",))
+ .build()
+}
+
+pub fn init_ops() -> Extension {
+ ops(&mut ext()).build()
}
pub enum HttpSocketAddr {