Skip to content

Commit

Permalink
Merge branch 'main' into foreign-function-callback
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrSikora authored Jan 15, 2025
2 parents 47ec2ec + 8604c64 commit b8c86fc
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 @@ -353,6 +353,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 @@ -409,6 +413,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 @@ -461,6 +469,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 @@ -517,6 +529,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 b8c86fc

Please sign in to comment.