From 953629913b7434e20d0b9243e8a6e1dd49387c92 Mon Sep 17 00:00:00 2001 From: nbn01 Date: Wed, 28 Aug 2024 12:09:55 +0530 Subject: [PATCH 1/4] add: remove_http_request_header convenient func Signed-off-by: nbn01 --- src/hostcalls.rs | 9 +++++++++ src/traits.rs | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/hostcalls.rs b/src/hostcalls.rs index 15687888..ed14d542 100644 --- a/src/hostcalls.rs +++ b/src/hostcalls.rs @@ -318,6 +318,15 @@ pub fn set_map_value(map_type: MapType, key: &str, value: Option<&str>) -> Resul } } +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), + } + } +} + pub fn set_map_value_bytes( map_type: MapType, key: &str, diff --git a/src/traits.rs b/src/traits.rs index bd54bcbe..b996a60c 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -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 } From d7a9eb575627e06c1857c156b07e70fa18061f07 Mon Sep 17 00:00:00 2001 From: Nandan B N Date: Mon, 28 Oct 2024 14:10:51 +0530 Subject: [PATCH 2/4] fix ordering of methods Signed-off-by: Nandan B N --- src/hostcalls.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hostcalls.rs b/src/hostcalls.rs index ed14d542..0b7add79 100644 --- a/src/hostcalls.rs +++ b/src/hostcalls.rs @@ -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 { @@ -318,6 +310,14 @@ 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()) { From b8811fc880b8e43fd0191928844c987aa492a8f4 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Wed, 15 Jan 2025 08:09:36 -0500 Subject: [PATCH 3/4] review: fix ordering. Signed-off-by: Piotr Sikora --- src/hostcalls.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/hostcalls.rs b/src/hostcalls.rs index 9d6e89f6..8dbc335c 100644 --- a/src/hostcalls.rs +++ b/src/hostcalls.rs @@ -278,6 +278,23 @@ pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result } } +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), + } + } +} + extern "C" { fn proxy_replace_header_map_value( map_type: MapType, @@ -310,23 +327,6 @@ 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), - } - } -} - pub fn set_map_value_bytes( map_type: MapType, key: &str, From 887d9cb1016936ed3c286d22e7fc84c4fd0b2059 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Wed, 15 Jan 2025 08:09:53 -0500 Subject: [PATCH 4/4] review: add missing functions in HttpContext trait. Signed-off-by: Piotr Sikora --- src/traits.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/traits.rs b/src/traits.rs index b996a60c..e0ae9477 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -411,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() } @@ -463,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 } @@ -519,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() }