From f55b02f2d9a3f1592119c8723e84cdc246d9ca1f Mon Sep 17 00:00:00 2001 From: jizhuozhi Date: Thu, 10 Oct 2024 21:02:36 +0800 Subject: [PATCH] feat: add example of http-dispatch --- .../Cargo.lock | 2 +- .../Cargo.toml | 2 +- .../Makefile | 2 +- .../README.md | 2 +- .../README_EN.md | 2 +- .../VERSION | 0 .../src/lib.rs | 26 +++++++++---------- plugins/wasm-rust/scripts/gen.sh | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) rename plugins/wasm-rust/example/{http-promise-example => http-dispatch-example}/Cargo.lock (99%) rename plugins/wasm-rust/example/{http-promise-example => http-dispatch-example}/Cargo.toml (93%) rename plugins/wasm-rust/example/{http-promise-example => http-dispatch-example}/Makefile (78%) rename plugins/wasm-rust/example/{http-promise-example => http-dispatch-example}/README.md (92%) rename plugins/wasm-rust/example/{http-promise-example => http-dispatch-example}/README_EN.md (92%) rename plugins/wasm-rust/example/{http-promise-example => http-dispatch-example}/VERSION (100%) rename plugins/wasm-rust/example/{http-promise-example => http-dispatch-example}/src/lib.rs (86%) diff --git a/plugins/wasm-rust/example/http-promise-example/Cargo.lock b/plugins/wasm-rust/example/http-dispatch-example/Cargo.lock similarity index 99% rename from plugins/wasm-rust/example/http-promise-example/Cargo.lock rename to plugins/wasm-rust/example/http-dispatch-example/Cargo.lock index 68d1c13049..7d3f61b915 100644 --- a/plugins/wasm-rust/example/http-promise-example/Cargo.lock +++ b/plugins/wasm-rust/example/http-dispatch-example/Cargo.lock @@ -84,7 +84,7 @@ dependencies = [ ] [[package]] -name = "http-promise-example" +name = "http-dispatch-example" version = "0.1.0" dependencies = [ "higress-wasm-rust", diff --git a/plugins/wasm-rust/example/http-promise-example/Cargo.toml b/plugins/wasm-rust/example/http-dispatch-example/Cargo.toml similarity index 93% rename from plugins/wasm-rust/example/http-promise-example/Cargo.toml rename to plugins/wasm-rust/example/http-dispatch-example/Cargo.toml index 9a0c20666e..c68ff20ac6 100644 --- a/plugins/wasm-rust/example/http-promise-example/Cargo.toml +++ b/plugins/wasm-rust/example/http-dispatch-example/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "http-promise-example" +name = "http-dispatch-example" version = "0.1.0" edition = "2021" publish = false diff --git a/plugins/wasm-rust/example/http-promise-example/Makefile b/plugins/wasm-rust/example/http-dispatch-example/Makefile similarity index 78% rename from plugins/wasm-rust/example/http-promise-example/Makefile rename to plugins/wasm-rust/example/http-dispatch-example/Makefile index 042046fa26..db0061daf7 100644 --- a/plugins/wasm-rust/example/http-promise-example/Makefile +++ b/plugins/wasm-rust/example/http-dispatch-example/Makefile @@ -3,7 +3,7 @@ BUILD_OPTS="--release" .DEFAULT: build: rustup target add wasm32-wasi - cargo build --target wasm32-wasi ${BUILD_OPTS} + cargo build --target wasm32-wasi find target -name "*.wasm" -d 3 -exec cp "{}" plugin.wasm \; clean: diff --git a/plugins/wasm-rust/example/http-promise-example/README.md b/plugins/wasm-rust/example/http-dispatch-example/README.md similarity index 92% rename from plugins/wasm-rust/example/http-promise-example/README.md rename to plugins/wasm-rust/example/http-dispatch-example/README.md index 8d16005090..b46e4b3fd1 100644 --- a/plugins/wasm-rust/example/http-promise-example/README.md +++ b/plugins/wasm-rust/example/http-dispatch-example/README.md @@ -1,5 +1,5 @@ --- -title: http-promise-example +title: http-dispatch-example keywords: description: --- diff --git a/plugins/wasm-rust/example/http-promise-example/README_EN.md b/plugins/wasm-rust/example/http-dispatch-example/README_EN.md similarity index 92% rename from plugins/wasm-rust/example/http-promise-example/README_EN.md rename to plugins/wasm-rust/example/http-dispatch-example/README_EN.md index affee75d67..1c16155512 100644 --- a/plugins/wasm-rust/example/http-promise-example/README_EN.md +++ b/plugins/wasm-rust/example/http-dispatch-example/README_EN.md @@ -1,5 +1,5 @@ --- -title: http-promise-example +title: http-dispatch-example keywords: description: --- diff --git a/plugins/wasm-rust/example/http-promise-example/VERSION b/plugins/wasm-rust/example/http-dispatch-example/VERSION similarity index 100% rename from plugins/wasm-rust/example/http-promise-example/VERSION rename to plugins/wasm-rust/example/http-dispatch-example/VERSION diff --git a/plugins/wasm-rust/example/http-promise-example/src/lib.rs b/plugins/wasm-rust/example/http-dispatch-example/src/lib.rs similarity index 86% rename from plugins/wasm-rust/example/http-promise-example/src/lib.rs rename to plugins/wasm-rust/example/http-dispatch-example/src/lib.rs index f744b42cf4..318cc9199c 100644 --- a/plugins/wasm-rust/example/http-promise-example/src/lib.rs +++ b/plugins/wasm-rust/example/http-dispatch-example/src/lib.rs @@ -25,35 +25,35 @@ use std::time::Duration; proxy_wasm::main! {{ proxy_wasm::set_log_level(LogLevel::Trace); - proxy_wasm::set_root_context(|_|Box::new(HttpPromiseExampleRoot::new())); + proxy_wasm::set_root_context(|_|Box::new(HttpDispatchExampleRoot::new())); }} -struct HttpPromiseExampleRoot { +struct HttpDispatchExampleRoot { log: Rc, - rule_matcher: SharedRuleMatcher, + rule_matcher: SharedRuleMatcher, } -struct HttpPromiseExample { +struct HttpDispatchExample { log: Rc, - rule_matcher: SharedRuleMatcher, + rule_matcher: SharedRuleMatcher, http_dispatcher: HttpDispatcher, } #[derive(Default, Clone, Debug, Deserialize)] -struct HttpPromiseExampleConfig {} +struct HttpDispatchExampleConfig {} -impl HttpPromiseExampleRoot { +impl HttpDispatchExampleRoot { fn new() -> Self { - HttpPromiseExampleRoot { + HttpDispatchExampleRoot { log: Rc::new(Log::new("http-promise-example".to_string())), rule_matcher: rule_matcher::new_shared(), } } } -impl Context for HttpPromiseExampleRoot {} +impl Context for HttpDispatchExampleRoot {} -impl RootContext for HttpPromiseExampleRoot { +impl RootContext for HttpDispatchExampleRoot { fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { on_configure( self, @@ -64,7 +64,7 @@ impl RootContext for HttpPromiseExampleRoot { } fn create_http_context(&self, _context_id: u32) -> Option> { - Some(Box::new(HttpPromiseExample { + Some(Box::new(HttpDispatchExample { log: self.log.clone(), rule_matcher: self.rule_matcher.clone(), http_dispatcher: Default::default(), @@ -76,7 +76,7 @@ impl RootContext for HttpPromiseExampleRoot { } } -impl Context for HttpPromiseExample { +impl Context for HttpDispatchExample { fn on_http_call_response( &mut self, _token_id: u32, @@ -89,7 +89,7 @@ impl Context for HttpPromiseExample { } } -impl HttpContext for HttpPromiseExample { +impl HttpContext for HttpDispatchExample { fn on_http_request_headers(&mut self, _: usize, _: bool) -> HeaderAction { let log = self.log.clone(); diff --git a/plugins/wasm-rust/scripts/gen.sh b/plugins/wasm-rust/scripts/gen.sh index e9976cc836..57bb3ed82c 100644 --- a/plugins/wasm-rust/scripts/gen.sh +++ b/plugins/wasm-rust/scripts/gen.sh @@ -73,7 +73,7 @@ srcdir="$workdir"/src mkdir -p "$workdir" mkdir -p "$srcdir" -cat -t >"$workdir/Makefile"<"$workdir/Makefile"<