From d61c8d3fc29556a75601dc1b15871e98db5fa2e8 Mon Sep 17 00:00:00 2001 From: nbn01 Date: Wed, 28 Aug 2024 12:09:55 +0530 Subject: [PATCH] add: remove_http_request_header convenient func --- 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 }