From e59e2249792a937c0461ae8beeb59c7b42f77b91 Mon Sep 17 00:00:00 2001 From: Ben Plotnick Date: Sat, 4 Jan 2025 22:18:57 +0000 Subject: [PATCH] Address review feedback Signed-off-by: Ben Plotnick --- .../dynamic_modules/sdk/rust/src/lib.rs | 21 +++++-------------- .../filters/http/dynamic_modules/abi_impl.cc | 3 +-- .../dynamic_modules/test_data/rust/http.rs | 2 +- .../test_data/rust/http_test.rs | 2 +- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs index 63ffbcb8188b..f2948fbd55a6 100644 --- a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs +++ b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs @@ -4,7 +4,6 @@ #![allow(dead_code)] pub mod buffer; -use abi::envoy_dynamic_module_type_module_http_header; pub use buffer::EnvoyBuffer; use mockall::predicate::*; use mockall::*; @@ -340,7 +339,7 @@ pub trait EnvoyHttpFilter { &mut self, status_code: u32, headers: Vec<(&'a str, &'b [u8])>, - body: Option<&'c str>, + body: Option<&'c [u8]>, ); } @@ -501,28 +500,18 @@ impl EnvoyHttpFilter for EnvoyHttpFilterImpl { } } - fn send_response(&mut self, status_code: u32, headers: Vec<(&str, &[u8])>, body: Option<&str>) { + fn send_response(&mut self, status_code: u32, headers: Vec<(&str, &[u8])>, body: Option<&[u8]>) { let body_ptr = body.map(|s| s.as_ptr()).unwrap_or(std::ptr::null()); let body_length = body.map(|s| s.len()).unwrap_or(0); - let headers_c: Vec = headers - .iter() - .map( - |(key, value)| envoy_dynamic_module_type_module_http_header { - key_ptr: key.as_ptr() as *mut _, - key_length: key.len(), - value_ptr: value.as_ptr() as *mut _, - value_length: value.len(), - }, - ) - .collect(); + let headers_ptr = headers.as_ptr() as *mut abi::envoy_dynamic_module_type_module_http_header; unsafe { abi::envoy_dynamic_module_callback_http_send_response( self.raw_ptr, status_code, - headers_c.as_ptr() as *mut _, - headers_c.len(), + headers_ptr, + headers.len(), body_ptr as *mut _, body_length, ) diff --git a/source/extensions/filters/http/dynamic_modules/abi_impl.cc b/source/extensions/filters/http/dynamic_modules/abi_impl.cc index 571fde020b87..1a87d2094436 100644 --- a/source/extensions/filters/http/dynamic_modules/abi_impl.cc +++ b/source/extensions/filters/http/dynamic_modules/abi_impl.cc @@ -1,4 +1,3 @@ -#include "source/common/common/logger.h" #include "source/extensions/dynamic_modules/abi.h" #include "source/extensions/filters/http/dynamic_modules/filter.h" @@ -213,7 +212,7 @@ void envoy_dynamic_module_callback_http_send_response( const absl::string_view key(static_cast(header->key_ptr), header->key_length); const absl::string_view value(static_cast(header->value_ptr), header->value_length); - headers.addCopy(Http::LowerCaseString(key), std::string(value)); + headers.addCopy(Http::LowerCaseString(key), value); } }; } diff --git a/test/extensions/dynamic_modules/test_data/rust/http.rs b/test/extensions/dynamic_modules/test_data/rust/http.rs index 18962999db6d..e65add5d8896 100644 --- a/test/extensions/dynamic_modules/test_data/rust/http.rs +++ b/test/extensions/dynamic_modules/test_data/rust/http.rs @@ -256,7 +256,7 @@ impl HttpFilter for SendResponseFilter { ("header1", "value1".as_bytes()), ("header2", "value2".as_bytes()), ], - Some("Hello, World!"), + Some(b"Hello, World!"), ); abi::envoy_dynamic_module_type_on_http_filter_request_headers_status::StopIteration } diff --git a/test/extensions/dynamic_modules/test_data/rust/http_test.rs b/test/extensions/dynamic_modules/test_data/rust/http_test.rs index 59a81d9a050f..6ffa066c61be 100644 --- a/test/extensions/dynamic_modules/test_data/rust/http_test.rs +++ b/test/extensions/dynamic_modules/test_data/rust/http_test.rs @@ -77,7 +77,7 @@ fn test_header_callbacks_on_request_headers_local_resp() { ("header1", "value1".as_bytes()), ("header2", "value2".as_bytes()), ] - && *body == Some("Hello, World!") + && *body == Some(b"Hello, World!") }) .once() .return_const(());