-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from 3scale-labs/dev/header-to-metadata
Dev/header to metadata
- Loading branch information
Showing
14 changed files
with
610 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.vscode/ | ||
envoy-rate-limit-header/target/ | ||
mock-backend/node_modules/ | ||
mock-backend/node_modules/ | ||
header-to-metadata/add-header-filter/target/ | ||
header-to-metadata/metadata-filter/target/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "add-header-filter" | ||
version = "0.1.0" | ||
authors = ["Lahiru Udayanga <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
proxy-wasm = "0.1.3" | ||
log = "0.4.14" | ||
wasm-bindgen = "0.2.74" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
build: add_header_filter.wasm | ||
|
||
add_header_filter.wasm: | ||
cargo build --target wasm32-unknown-unknown --release | ||
cp target/wasm32-unknown-unknown/release/add_header_filter.wasm ../build/add_header_filter.wasm | ||
|
||
.PHONY: clean | ||
clean: | ||
rm ../build/add_header_filter.wasm || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use log::info; | ||
use proxy_wasm::traits::*; | ||
use proxy_wasm::types::*; | ||
|
||
#[no_mangle] | ||
pub fn _start() { | ||
proxy_wasm::set_log_level(LogLevel::Info); | ||
proxy_wasm::set_root_context(|_| -> Box<dyn RootContext> { Box::new(HttpHeadersRoot) }); | ||
} | ||
|
||
struct HttpHeadersRoot; | ||
|
||
impl Context for HttpHeadersRoot {} | ||
|
||
impl RootContext for HttpHeadersRoot { | ||
fn get_type(&self) -> Option<ContextType> { | ||
Some(ContextType::HttpContext) | ||
} | ||
|
||
fn create_http_context(&self, context_id: u32) -> Option<Box<dyn HttpContext>> { | ||
Some(Box::new(HttpHeaders { context_id })) | ||
} | ||
} | ||
|
||
struct HttpHeaders { | ||
context_id: u32, | ||
} | ||
|
||
impl Context for HttpHeaders {} | ||
|
||
impl HttpContext for HttpHeaders { | ||
fn on_http_request_headers(&mut self, _: usize) -> Action { | ||
// Add metadata headers. These metadata headers will be added as dynamic metadata from the header to metadata filter. | ||
self.add_http_request_header("x-3scale-service-key", "123456789"); | ||
self.add_http_request_header("x-3scale-application-key", "987654321"); | ||
info!("3scale metadata headers added from the request path"); | ||
Action::Continue | ||
} | ||
|
||
fn on_log(&mut self) { | ||
info!("#{} completed.", self.context_id); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: '3.7' | ||
services: | ||
envoy: | ||
build: | ||
context: ./ | ||
dockerfile: ./resources/Dockerfile | ||
depends_on: | ||
- backend_service | ||
networks: | ||
- envoymesh | ||
ports: | ||
- "9095:9095" | ||
- "9000:9000" | ||
|
||
backend_service: | ||
build: | ||
context: ../mock-backend | ||
dockerfile: Dockerfile | ||
networks: | ||
- envoymesh | ||
|
||
networks: | ||
envoymesh: {} |
Oops, something went wrong.