Skip to content

Commit

Permalink
Plugin allow not percent encode (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
4t145 authored Jun 27, 2024
1 parent 4f836c4 commit 6b4a4c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
3 changes: 3 additions & 0 deletions backend/spi/spi-plugin/src/dto/plugin_exec_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub struct PluginExecReq {
pub header: Option<HashMap<String, String>>,
pub query: Option<HashMap<String, String>>,
pub body: Option<Value>,
#[serde(default)]
#[oai(default)]
pub percent_encode: Option<bool>,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug, Clone)]
Expand Down
15 changes: 10 additions & 5 deletions backend/spi/spi-plugin/src/serv/plugin_exec_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?
);
Expand Down Expand Up @@ -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<HashMap<String, String>>, body: Option<Value>, funs: &TardisFunsInst) -> TardisResult<String> {
fn build_url(path: &str, query: Option<HashMap<String, String>>, body: Option<Value>, percent_encode: bool, funs: &TardisFunsInst) -> TardisResult<String> {
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)| {
Expand All @@ -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
});
Expand Down

0 comments on commit 6b4a4c9

Please sign in to comment.