Skip to content

Commit 8604c64

Browse files
authored
Add convenience functions to remove headers and trailers. (#256)
Signed-off-by: Nandan B N <[email protected]>
1 parent f14c4f6 commit 8604c64

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/hostcalls.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,29 @@ pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result<Option<Bytes>
279279
}
280280

281281
extern "C" {
282-
fn proxy_replace_header_map_value(
282+
fn proxy_remove_header_map_value(
283283
map_type: MapType,
284284
key_data: *const u8,
285285
key_size: usize,
286-
value_data: *const u8,
287-
value_size: usize,
288286
) -> Status;
289287
}
290288

289+
pub fn remove_map_value(map_type: MapType, key: &str) -> Result<(), Status> {
290+
unsafe {
291+
match proxy_remove_header_map_value(map_type, key.as_ptr(), key.len()) {
292+
Status::Ok => Ok(()),
293+
status => panic!("unexpected status: {}", status as u32),
294+
}
295+
}
296+
}
297+
291298
extern "C" {
292-
fn proxy_remove_header_map_value(
299+
fn proxy_replace_header_map_value(
293300
map_type: MapType,
294301
key_data: *const u8,
295302
key_size: usize,
303+
value_data: *const u8,
304+
value_size: usize,
296305
) -> Status;
297306
}
298307

src/traits.rs

+16
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ pub trait HttpContext: Context {
351351
hostcalls::add_map_value_bytes(MapType::HttpRequestHeaders, name, value).unwrap()
352352
}
353353

354+
fn remove_http_request_header(&self, name: &str) {
355+
hostcalls::remove_map_value(MapType::HttpRequestHeaders, name).unwrap()
356+
}
357+
354358
fn on_http_request_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action {
355359
Action::Continue
356360
}
@@ -407,6 +411,10 @@ pub trait HttpContext: Context {
407411
hostcalls::add_map_value_bytes(MapType::HttpRequestTrailers, name, value).unwrap()
408412
}
409413

414+
fn remove_http_request_trailer(&self, name: &str) {
415+
hostcalls::remove_map_value(MapType::HttpRequestTrailers, name).unwrap()
416+
}
417+
410418
fn resume_http_request(&self) {
411419
hostcalls::resume_http_request().unwrap()
412420
}
@@ -459,6 +467,10 @@ pub trait HttpContext: Context {
459467
hostcalls::add_map_value_bytes(MapType::HttpResponseHeaders, name, value).unwrap()
460468
}
461469

470+
fn remove_http_response_header(&self, name: &str) {
471+
hostcalls::remove_map_value(MapType::HttpResponseHeaders, name).unwrap()
472+
}
473+
462474
fn on_http_response_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action {
463475
Action::Continue
464476
}
@@ -515,6 +527,10 @@ pub trait HttpContext: Context {
515527
hostcalls::add_map_value_bytes(MapType::HttpResponseTrailers, name, value).unwrap()
516528
}
517529

530+
fn remove_http_response_trailer(&self, name: &str) {
531+
hostcalls::remove_map_value(MapType::HttpResponseTrailers, name).unwrap()
532+
}
533+
518534
fn resume_http_response(&self) {
519535
hostcalls::resume_http_response().unwrap()
520536
}

0 commit comments

Comments
 (0)