mirror of
https://github.com/alibaba/higress.git
synced 2026-02-06 15:10:54 +08:00
Ai data masking fix (#1420)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
## Wasm 插件
|
## Wasm 插件
|
||||||
|
|
||||||
|
|
||||||
目前 Higress 提供了 c++ 和 golang 两种 Wasm 插件开发框架,支持 Wasm 插件路由&域名级匹配生效。
|
目前 Higress 提供了 c++ 和 golang 两种 Wasm 插件开发框架,支持 Wasm 插件路由&域名级匹配生效。
|
||||||
|
|
||||||
同时提供了多个内置插件,用户可以基于 Higress 提供的官方镜像仓库直接使用这些插件(以 c++ 版本举例):
|
同时提供了多个内置插件,用户可以基于 Higress 提供的官方镜像仓库直接使用这些插件(以 c++ 版本举例):
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use fancy_regex::Regex;
|
|||||||
use grok::patterns;
|
use grok::patterns;
|
||||||
use higress_wasm_rust::log::Log;
|
use higress_wasm_rust::log::Log;
|
||||||
use higress_wasm_rust::plugin_wrapper::{HttpContextWrapper, RootContextWrapper};
|
use higress_wasm_rust::plugin_wrapper::{HttpContextWrapper, RootContextWrapper};
|
||||||
|
use higress_wasm_rust::request_wrapper::has_request_body;
|
||||||
use higress_wasm_rust::rule_matcher::{on_configure, RuleMatcher, SharedRuleMatcher};
|
use higress_wasm_rust::rule_matcher::{on_configure, RuleMatcher, SharedRuleMatcher};
|
||||||
use jieba_rs::Jieba;
|
use jieba_rs::Jieba;
|
||||||
use jsonpath_rust::{JsonPath, JsonPathValue};
|
use jsonpath_rust::{JsonPath, JsonPathValue};
|
||||||
@@ -519,7 +520,11 @@ impl HttpContext for AiDataMasking {
|
|||||||
_num_headers: usize,
|
_num_headers: usize,
|
||||||
_end_of_stream: bool,
|
_end_of_stream: bool,
|
||||||
) -> HeaderAction {
|
) -> HeaderAction {
|
||||||
HeaderAction::StopIteration
|
if has_request_body() {
|
||||||
|
HeaderAction::StopIteration
|
||||||
|
} else {
|
||||||
|
HeaderAction::Continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn on_http_response_headers(
|
fn on_http_response_headers(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -669,14 +674,12 @@ impl HttpContextWrapper<AiDataMaskingConfig> for AiDataMasking {
|
|||||||
}
|
}
|
||||||
fn on_http_response_complete_body(&mut self, res_body: &Bytes) -> DataAction {
|
fn on_http_response_complete_body(&mut self, res_body: &Bytes) -> DataAction {
|
||||||
if self.config.is_none() {
|
if self.config.is_none() {
|
||||||
self.reset_http_response();
|
|
||||||
return DataAction::Continue;
|
return DataAction::Continue;
|
||||||
}
|
}
|
||||||
let config = self.config.as_ref().unwrap();
|
let config = self.config.as_ref().unwrap();
|
||||||
let mut res_body = match String::from_utf8(res_body.clone()) {
|
let mut res_body = match String::from_utf8(res_body.clone()) {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.reset_http_response();
|
|
||||||
return DataAction::Continue;
|
return DataAction::Continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -309,7 +309,9 @@ where
|
|||||||
fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> HeaderAction {
|
fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> HeaderAction {
|
||||||
let binding = self.rule_matcher.borrow();
|
let binding = self.rule_matcher.borrow();
|
||||||
self.config = binding.get_match_config().map(|config| config.1.clone());
|
self.config = binding.get_match_config().map(|config| config.1.clone());
|
||||||
|
if self.config.is_none() {
|
||||||
|
return HeaderAction::Continue;
|
||||||
|
}
|
||||||
for (k, v) in self.get_http_request_headers_bytes() {
|
for (k, v) in self.get_http_request_headers_bytes() {
|
||||||
match String::from_utf8(v) {
|
match String::from_utf8(v) {
|
||||||
Ok(header_value) => {
|
Ok(header_value) => {
|
||||||
@@ -340,6 +342,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_http_request_body(&mut self, body_size: usize, end_of_stream: bool) -> DataAction {
|
fn on_http_request_body(&mut self, body_size: usize, end_of_stream: bool) -> DataAction {
|
||||||
|
if self.config.is_none() {
|
||||||
|
return DataAction::Continue;
|
||||||
|
}
|
||||||
if !self.http_content.borrow().cache_request_body() {
|
if !self.http_content.borrow().cache_request_body() {
|
||||||
return self
|
return self
|
||||||
.http_content
|
.http_content
|
||||||
@@ -362,6 +367,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_http_request_trailers(&mut self, num_trailers: usize) -> Action {
|
fn on_http_request_trailers(&mut self, num_trailers: usize) -> Action {
|
||||||
|
if self.config.is_none() {
|
||||||
|
return Action::Continue;
|
||||||
|
}
|
||||||
self.http_content
|
self.http_content
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.on_http_request_trailers(num_trailers)
|
.on_http_request_trailers(num_trailers)
|
||||||
@@ -372,6 +380,9 @@ where
|
|||||||
num_headers: usize,
|
num_headers: usize,
|
||||||
end_of_stream: bool,
|
end_of_stream: bool,
|
||||||
) -> HeaderAction {
|
) -> HeaderAction {
|
||||||
|
if self.config.is_none() {
|
||||||
|
return HeaderAction::Continue;
|
||||||
|
}
|
||||||
for (k, v) in self.get_http_response_headers_bytes() {
|
for (k, v) in self.get_http_response_headers_bytes() {
|
||||||
match String::from_utf8(v) {
|
match String::from_utf8(v) {
|
||||||
Ok(header_value) => {
|
Ok(header_value) => {
|
||||||
@@ -399,6 +410,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_http_response_body(&mut self, body_size: usize, end_of_stream: bool) -> DataAction {
|
fn on_http_response_body(&mut self, body_size: usize, end_of_stream: bool) -> DataAction {
|
||||||
|
if self.config.is_none() {
|
||||||
|
return DataAction::Continue;
|
||||||
|
}
|
||||||
if !self.http_content.borrow().cache_response_body() {
|
if !self.http_content.borrow().cache_response_body() {
|
||||||
return self
|
return self
|
||||||
.http_content
|
.http_content
|
||||||
@@ -423,6 +437,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_http_response_trailers(&mut self, num_trailers: usize) -> Action {
|
fn on_http_response_trailers(&mut self, num_trailers: usize) -> Action {
|
||||||
|
if self.config.is_none() {
|
||||||
|
return Action::Continue;
|
||||||
|
}
|
||||||
self.http_content
|
self.http_content
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.on_http_response_trailers(num_trailers)
|
.on_http_response_trailers(num_trailers)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ pub fn has_request_body() -> bool {
|
|||||||
content_type, content_length_str, transfer_encoding
|
content_type, content_length_str, transfer_encoding
|
||||||
)
|
)
|
||||||
).unwrap();
|
).unwrap();
|
||||||
if !content_type.is_some_and(|x| !x.is_empty()) {
|
if content_type.is_some_and(|x| !x.is_empty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if let Some(cl) = content_length_str {
|
if let Some(cl) = content_length_str {
|
||||||
|
|||||||
Reference in New Issue
Block a user