Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: remove_http_request_header convenient func #256

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/hostcalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,6 @@ extern "C" {
) -> Status;
}

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

pub fn set_map_value(map_type: MapType, key: &str, value: Option<&str>) -> Result<(), Status> {
unsafe {
if let Some(value) = value {
Expand All @@ -318,6 +310,23 @@ pub fn set_map_value(map_type: MapType, key: &str, value: Option<&str>) -> Resul
}
}

extern "C" {
fn proxy_remove_header_map_value(
map_type: MapType,
key_data: *const u8,
key_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),
}
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Could you move it above, so that it's not in-between set_map_value and set_map_value_bytes?

Ideally, could you group it with the extern C prototype, so that it's:

extern "C" {
    fn proxy_remove_header_map_value(
    [...]
}

pub fn remove_map_value(map_type: MapType, key: &str) -> Result<(), Status> {
[...]

extern "C" {
    fn proxy_replace_header_map_value(
    [...]
}

pub fn set_map_value(map_type: MapType, key: &str, value: Option<&str>) -> Result<(), Status> {
[...]

to match the existing style in this file?

pub fn set_map_value_bytes(
map_type: MapType,
key: &str,
Expand Down
4 changes: 4 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add those for request trailer, response header and response trailer as well? Thanks!

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
Loading