From 345678d087883d02bf22c80ed824435fc6adecc1 Mon Sep 17 00:00:00 2001 From: Martijn Swaagman Date: Thu, 28 Nov 2024 10:26:22 +0100 Subject: [PATCH] chore: implement suggestion Signed-off-by: Martijn Swaagman --- README.md | 2 +- .../Cargo.toml | 4 ++-- .../README.md | 10 +++++----- .../docker-compose.yaml | 0 .../envoy.yaml | 8 ++++---- .../src/lib.rs | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) rename examples/{filter_metadata => envoy_filter_metadata}/Cargo.toml (73%) rename examples/{filter_metadata => envoy_filter_metadata}/README.md (71%) rename examples/{filter_metadata => envoy_filter_metadata}/docker-compose.yaml (100%) rename examples/{filter_metadata => envoy_filter_metadata}/envoy.yaml (92%) rename examples/{filter_metadata => envoy_filter_metadata}/src/lib.rs (88%) diff --git a/README.md b/README.md index 97a9dc5..fa53c22 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ - [HTTP Response body](./examples/http_body/) - [HTTP Configuration](./examples/http_config/) - [gRPC Auth (random)](./examples/grpc_auth_random/) -- [Filter metadata](./examples/filter_metadata/) +- [Envoy filter metadata](./examples/envoy_filter_metadata/) ## Articles & blog posts from the community diff --git a/examples/filter_metadata/Cargo.toml b/examples/envoy_filter_metadata/Cargo.toml similarity index 73% rename from examples/filter_metadata/Cargo.toml rename to examples/envoy_filter_metadata/Cargo.toml index 5916bb4..86bd93a 100644 --- a/examples/filter_metadata/Cargo.toml +++ b/examples/envoy_filter_metadata/Cargo.toml @@ -1,9 +1,9 @@ [package] publish = false -name = "proxy-wasm-example-filter-metadata" +name = "proxy-wasm-example-envoy-filter-metadata" version = "0.0.1" authors = ["Martijn Swaagma "] -description = "Proxy-Wasm plugin example: Filter metadata" +description = "Proxy-Wasm plugin example: Envoy filter metadata" license = "Apache-2.0" edition = "2018" diff --git a/examples/filter_metadata/README.md b/examples/envoy_filter_metadata/README.md similarity index 71% rename from examples/filter_metadata/README.md rename to examples/envoy_filter_metadata/README.md index 13eb08e..8a6251d 100644 --- a/examples/filter_metadata/README.md +++ b/examples/envoy_filter_metadata/README.md @@ -1,6 +1,6 @@ -## Proxy-Wasm plugin example: Metadata +## Proxy-Wasm plugin example: Envoy metadata -Proxy-Wasm plugin that demonstrates reading metadata set by other filters +Proxy-Wasm plugin that demonstrates reading metadata set by other Envoy filters ### Building @@ -24,10 +24,10 @@ $ curl localhost:10000/ Welcome, set the `x-custom-metadata` header to change the response! ``` - -Send a HTTP request to `localhost:10000/` with a `x-custom-metadata` header value. +Send a HTTP request to `localhost:10000/` with a `x-custom-metadata` header value to get the uppercased value in the response. +The response will also set a response header `uppercased-metadata: SOME-VALUE`. ```sh $ curl localhost:10000/ -H "x-custom-metadata: some-value" -Custom response with `x-custom-metadata` value "some-value" +Custom response with Envoy metadata: "SOME-VALUE"! ``` diff --git a/examples/filter_metadata/docker-compose.yaml b/examples/envoy_filter_metadata/docker-compose.yaml similarity index 100% rename from examples/filter_metadata/docker-compose.yaml rename to examples/envoy_filter_metadata/docker-compose.yaml diff --git a/examples/filter_metadata/envoy.yaml b/examples/envoy_filter_metadata/envoy.yaml similarity index 92% rename from examples/filter_metadata/envoy.yaml rename to examples/envoy_filter_metadata/envoy.yaml index 083398c..e598af5 100644 --- a/examples/filter_metadata/envoy.yaml +++ b/examples/envoy_filter_metadata/envoy.yaml @@ -39,7 +39,7 @@ static_resources: body: inline_string: "Welcome, set the `x-custom-metadata` header to change the response!\n" http_filters: - # Set metadata + # Set uppercase metadata in Lua filter - name: envoy.filters.http.lua typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua @@ -50,7 +50,7 @@ static_resources: local data = headers:get("x-custom-metadata") if data then - request_handle:streamInfo():dynamicMetadata():set("envoy.filters.http.lua", "x-custom-metadata", data) + request_handle:streamInfo():dynamicMetadata():set("envoy.filters.http.lua", "uppercased-custom-metadata", string.upper(data)) end request_handle:logInfo("Metadata set by lua filter") @@ -62,12 +62,12 @@ static_resources: type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm value: config: - name: "metadata_filter" + name: "envoy_metadata_filter" vm_config: runtime: "envoy.wasm.runtime.v8" code: local: - filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_filter_metadata.wasm" + filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_envoy_filter_metadata.wasm" - name: envoy.filters.http.router typed_config: "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router diff --git a/examples/filter_metadata/src/lib.rs b/examples/envoy_filter_metadata/src/lib.rs similarity index 88% rename from examples/filter_metadata/src/lib.rs rename to examples/envoy_filter_metadata/src/lib.rs index 9017e3a..febdb74 100644 --- a/examples/filter_metadata/src/lib.rs +++ b/examples/envoy_filter_metadata/src/lib.rs @@ -31,16 +31,16 @@ impl HttpContext for MetadataHttp { "metadata", "filter_metadata", "envoy.filters.http.lua", - "x-custom-metadata", + "uppercased-custom-metadata", ]) { Some(metadata) => match String::from_utf8(metadata) { Ok(data) => { self.send_http_response( 200, - vec![("Powered-By", "proxy-wasm")], + vec![("Powered-By", "proxy-wasm"), ("uppercased-metadata", &data)], Some( format!( - "Custom response with `x-custom-metadata` value {:?}!\n", + "Custom response with Envoy metadata: {:?}!\n", data ) .as_bytes(),