Skip to content

Commit

Permalink
Add convenience functions to remove headers and trailers. (#256)
Browse files Browse the repository at this point in the history
Signed-off-by: Nandan B N <[email protected]>
  • Loading branch information
itsLucario authored Jan 15, 2025
1 parent f14c4f6 commit 8604c64
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/hostcalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,29 @@ pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result<Option<Bytes>
}

extern "C" {
fn proxy_replace_header_map_value(
fn proxy_remove_header_map_value(
map_type: MapType,
key_data: *const u8,
key_size: usize,
value_data: *const u8,
value_size: usize,
) -> Status;
}

pub fn remove_map_value(map_type: MapType, key: &str) -> Result<(), Status> {
unsafe {
match proxy_remove_header_map_value(map_type, key.as_ptr(), key.len()) {
Status::Ok => Ok(()),
status => panic!("unexpected status: {}", status as u32),
}
}
}

extern "C" {
fn proxy_remove_header_map_value(
fn proxy_replace_header_map_value(
map_type: MapType,
key_data: *const u8,
key_size: usize,
value_data: *const u8,
value_size: usize,
) -> Status;
}

Expand Down
16 changes: 16 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ pub trait HttpContext: Context {
hostcalls::add_map_value_bytes(MapType::HttpRequestHeaders, name, value).unwrap()
}

fn remove_http_request_header(&self, name: &str) {
hostcalls::remove_map_value(MapType::HttpRequestHeaders, name).unwrap()
}

fn on_http_request_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action {
Action::Continue
}
Expand Down Expand Up @@ -407,6 +411,10 @@ pub trait HttpContext: Context {
hostcalls::add_map_value_bytes(MapType::HttpRequestTrailers, name, value).unwrap()
}

fn remove_http_request_trailer(&self, name: &str) {
hostcalls::remove_map_value(MapType::HttpRequestTrailers, name).unwrap()
}

fn resume_http_request(&self) {
hostcalls::resume_http_request().unwrap()
}
Expand Down Expand Up @@ -459,6 +467,10 @@ pub trait HttpContext: Context {
hostcalls::add_map_value_bytes(MapType::HttpResponseHeaders, name, value).unwrap()
}

fn remove_http_response_header(&self, name: &str) {
hostcalls::remove_map_value(MapType::HttpResponseHeaders, name).unwrap()
}

fn on_http_response_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action {
Action::Continue
}
Expand Down Expand Up @@ -515,6 +527,10 @@ pub trait HttpContext: Context {
hostcalls::add_map_value_bytes(MapType::HttpResponseTrailers, name, value).unwrap()
}

fn remove_http_response_trailer(&self, name: &str) {
hostcalls::remove_map_value(MapType::HttpResponseTrailers, name).unwrap()
}

fn resume_http_response(&self) {
hostcalls::resume_http_response().unwrap()
}
Expand Down

0 comments on commit 8604c64

Please sign in to comment.