Skip to content

Commit b8c86fc

Browse files
authored
Merge branch 'main' into foreign-function-callback
2 parents 47ec2ec + 8604c64 commit b8c86fc

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/hostcalls.rs

Lines changed: 13 additions & 4 deletions
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ pub trait HttpContext: Context {
353353
hostcalls::add_map_value_bytes(MapType::HttpRequestHeaders, name, value).unwrap()
354354
}
355355

356+
fn remove_http_request_header(&self, name: &str) {
357+
hostcalls::remove_map_value(MapType::HttpRequestHeaders, name).unwrap()
358+
}
359+
356360
fn on_http_request_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action {
357361
Action::Continue
358362
}
@@ -409,6 +413,10 @@ pub trait HttpContext: Context {
409413
hostcalls::add_map_value_bytes(MapType::HttpRequestTrailers, name, value).unwrap()
410414
}
411415

416+
fn remove_http_request_trailer(&self, name: &str) {
417+
hostcalls::remove_map_value(MapType::HttpRequestTrailers, name).unwrap()
418+
}
419+
412420
fn resume_http_request(&self) {
413421
hostcalls::resume_http_request().unwrap()
414422
}
@@ -461,6 +469,10 @@ pub trait HttpContext: Context {
461469
hostcalls::add_map_value_bytes(MapType::HttpResponseHeaders, name, value).unwrap()
462470
}
463471

472+
fn remove_http_response_header(&self, name: &str) {
473+
hostcalls::remove_map_value(MapType::HttpResponseHeaders, name).unwrap()
474+
}
475+
464476
fn on_http_response_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action {
465477
Action::Continue
466478
}
@@ -517,6 +529,10 @@ pub trait HttpContext: Context {
517529
hostcalls::add_map_value_bytes(MapType::HttpResponseTrailers, name, value).unwrap()
518530
}
519531

532+
fn remove_http_response_trailer(&self, name: &str) {
533+
hostcalls::remove_map_value(MapType::HttpResponseTrailers, name).unwrap()
534+
}
535+
520536
fn resume_http_response(&self) {
521537
hostcalls::resume_http_response().unwrap()
522538
}

0 commit comments

Comments
 (0)