From 6b4a4c93729f04b1768b01d33ca89eb719e3bfed Mon Sep 17 00:00:00 2001 From: 4t145 Date: Thu, 27 Jun 2024 18:41:06 +0800 Subject: [PATCH] Plugin allow not percent encode (#790) --- Cargo.toml | 4 ++-- backend/spi/spi-plugin/src/dto/plugin_exec_dto.rs | 3 +++ .../spi/spi-plugin/src/serv/plugin_exec_serv.rs | 15 ++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee85b6ea3..583d193de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,9 +62,9 @@ rust_decimal_macros = { version = "1" } testcontainers-modules = { version = "0.3", features = ["redis"] } strum = { version = "0.26", features = ["derive"] } # tardis -# tardis = { version = "0.1.0-rc.15" } +tardis = { version = "0.1.0-rc.16" } # tardis = { path = "../tardis/tardis" } -tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "366f128" } +# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "366f128" } #spacegate # spacegate-shell = { path = "../spacegate/crates/shell", features = [ diff --git a/backend/spi/spi-plugin/src/dto/plugin_exec_dto.rs b/backend/spi/spi-plugin/src/dto/plugin_exec_dto.rs index b65cdc97a..0e3847d85 100644 --- a/backend/spi/spi-plugin/src/dto/plugin_exec_dto.rs +++ b/backend/spi/spi-plugin/src/dto/plugin_exec_dto.rs @@ -8,6 +8,9 @@ pub struct PluginExecReq { pub header: Option>, pub query: Option>, pub body: Option, + #[serde(default)] + #[oai(default)] + pub percent_encode: Option, } #[derive(poem_openapi::Object, Serialize, Deserialize, Debug, Clone)] diff --git a/backend/spi/spi-plugin/src/serv/plugin_exec_serv.rs b/backend/spi/spi-plugin/src/serv/plugin_exec_serv.rs index ae0eacf4b..345b92b84 100644 --- a/backend/spi/spi-plugin/src/serv/plugin_exec_serv.rs +++ b/backend/spi/spi-plugin/src/serv/plugin_exec_serv.rs @@ -31,6 +31,7 @@ impl PluginExecServ { &format!("{}{}", if spi_api.path_and_query.starts_with('/') { "" } else { "/" }, &spi_api.path_and_query), exec_req.query, exec_req.body.clone(), + exec_req.percent_encode.unwrap_or(false), funs, )? ); @@ -74,10 +75,14 @@ impl PluginExecServ { return Err(funs.err().not_found(&PluginApiServ::get_obj_name(), "exec", "exec api is not fond", "")); } - fn build_url(path: &str, query: Option>, body: Option, funs: &TardisFunsInst) -> TardisResult { + fn build_url(path: &str, query: Option>, body: Option, percent_encode: bool, funs: &TardisFunsInst) -> TardisResult { let mut path = path.to_string(); - fn enc(s: &str) -> percent_encoding::PercentEncode<'_> { - percent_encoding::utf8_percent_encode(s, percent_encoding::NON_ALPHANUMERIC) + let enc = if percent_encode { percent_encode_fn } else { not_encode_fn }; + fn percent_encode_fn(s: &str) -> String { + percent_encoding::utf8_percent_encode(s, percent_encoding::NON_ALPHANUMERIC).to_string() + } + fn not_encode_fn(s: &str) -> String { + s.to_string() } if let Some(query) = query { let query_str = query.iter().fold(String::default(), |mut s, (k, v)| { @@ -87,10 +92,10 @@ impl PluginExecServ { if !s.is_empty() { s.push('&') } - s.extend(enc(k)); + s.push_str(&enc(k)); if !v.is_empty() { s.push('='); - s.extend(enc(v)); + s.push_str(&enc(v)); } s });