Skip to content

Commit

Permalink
feat: add example of http-dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhuozhi committed Oct 10, 2024
1 parent b2a1f37 commit f55b02f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "http-promise-example"
name = "http-dispatch-example"
version = "0.1.0"
edition = "2021"
publish = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: http-promise-example
title: http-dispatch-example
keywords:
description:
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: http-promise-example
title: http-dispatch-example
keywords:
description:
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Log>,
rule_matcher: SharedRuleMatcher<HttpPromiseExampleConfig>,
rule_matcher: SharedRuleMatcher<HttpDispatchExampleConfig>,
}

struct HttpPromiseExample {
struct HttpDispatchExample {
log: Rc<Log>,
rule_matcher: SharedRuleMatcher<HttpPromiseExampleConfig>,
rule_matcher: SharedRuleMatcher<HttpDispatchExampleConfig>,
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,
Expand All @@ -64,7 +64,7 @@ impl RootContext for HttpPromiseExampleRoot {
}

fn create_http_context(&self, _context_id: u32) -> Option<Box<dyn HttpContext>> {
Some(Box::new(HttpPromiseExample {
Some(Box::new(HttpDispatchExample {
log: self.log.clone(),
rule_matcher: self.rule_matcher.clone(),
http_dispatcher: Default::default(),
Expand All @@ -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,
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion plugins/wasm-rust/scripts/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ srcdir="$workdir"/src
mkdir -p "$workdir"
mkdir -p "$srcdir"

cat -t >"$workdir/Makefile"<<EOF
cat >"$workdir/Makefile"<<EOF
BUILD_OPTS="--release"
.DEFAULT:
Expand Down

0 comments on commit f55b02f

Please sign in to comment.