Skip to content

Commit c9a2095

Browse files
committed
feat(filter): add gzip in filter chain, update ffi api to add response headers when creating body filter
1 parent a298f0a commit c9a2095

File tree

13 files changed

+554
-376
lines changed

13 files changed

+554
-376
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ cfg-if = "1.0.0"
2525
chrono = { version = "0.4.22", features = ["serde"] }
2626
cidr = { version = "0.2.1", features = ["serde"] }
2727
console_log = "0.2.0"
28+
flate2 = "1.0.24"
2829
heck = "0.4.0"
2930
http = "0.2.8"
3031
lazy_static = "1.4.0"

src/action/ffi.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ pub unsafe extern "C" fn redirectionio_action_header_filter_filter(
9393
pub unsafe extern "C" fn redirectionio_action_body_filter_create(
9494
_action: *mut Action,
9595
response_status_code: u16,
96+
response_header_map: *const HeaderMap,
9697
) -> *const FilterBodyAction {
9798
if _action.is_null() {
9899
return null() as *const FilterBodyAction;
99100
}
100101

101102
let action = &mut *_action;
103+
let headers = header_map_to_http_headers(response_header_map);
102104

103-
match action.create_filter_body(response_status_code) {
105+
match action.create_filter_body(response_status_code, &headers) {
104106
None => null(),
105107
Some(filter_body) => Box::into_raw(Box::new(filter_body)),
106108
}
@@ -115,14 +117,9 @@ pub unsafe extern "C" fn redirectionio_action_body_filter_filter(_filter: *mut F
115117
let filter = &mut *_filter;
116118
let bytes = buffer.into_vec();
117119

118-
let body = match String::from_utf8(bytes) {
119-
Err(error) => return Buffer::from_vec(error.into_bytes()),
120-
Ok(body) => body,
121-
};
122-
123-
let new_body = filter.filter(body);
120+
let new_body = filter.filter(bytes);
124121

125-
Buffer::from_string(new_body)
122+
Buffer::from_vec(new_body)
126123
}
127124

128125
#[no_mangle]
@@ -134,7 +131,7 @@ pub unsafe extern "C" fn redirectionio_action_body_filter_close(_filter: *mut Fi
134131
let mut filter = Box::from_raw(_filter);
135132
let end_body = filter.end();
136133

137-
Buffer::from_string(end_body)
134+
Buffer::from_vec(end_body)
138135
}
139136

140137
#[no_mangle]

src/action/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl Action {
396396
new_headers
397397
}
398398

399-
pub fn create_filter_body(&mut self, response_status_code: u16) -> Option<FilterBodyAction> {
399+
pub fn create_filter_body(&mut self, response_status_code: u16, headers: &[Header]) -> Option<FilterBodyAction> {
400400
let mut filters = Vec::new();
401401
let rule_applied = self.rule_traces.is_some();
402402

@@ -412,7 +412,7 @@ impl Action {
412412
filters.push(filter.filter);
413413
}
414414

415-
let body_filter = FilterBodyAction::new(filters);
415+
let body_filter = FilterBodyAction::new(filters, headers);
416416

417417
if body_filter.is_empty() {
418418
None

0 commit comments

Comments
 (0)