Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Plotnick <[email protected]>
  • Loading branch information
bplotnick committed Jan 4, 2025
1 parent 304c395 commit e59e224
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
21 changes: 5 additions & 16 deletions source/extensions/dynamic_modules/sdk/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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]>,
);
}

Expand Down Expand Up @@ -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<envoy_dynamic_module_type_module_http_header> = 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,
)
Expand Down
3 changes: 1 addition & 2 deletions source/extensions/filters/http/dynamic_modules/abi_impl.cc
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -213,7 +212,7 @@ void envoy_dynamic_module_callback_http_send_response(
const absl::string_view key(static_cast<const char*>(header->key_ptr), header->key_length);
const absl::string_view value(static_cast<const char*>(header->value_ptr),
header->value_length);
headers.addCopy(Http::LowerCaseString(key), std::string(value));
headers.addCopy(Http::LowerCaseString(key), value);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion test/extensions/dynamic_modules/test_data/rust/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl<EHF: EnvoyHttpFilter> HttpFilter<EHF> 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down

0 comments on commit e59e224

Please sign in to comment.