Skip to content

Commit daac9ed

Browse files
authored
Update wagi.rs
modify parse WagiHttp request params to command-line arguments
1 parent 0126b61 commit daac9ed

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

crates/trigger-http/src/wagi.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ impl HttpExecutor for WagiHttpExecutor {
3838
// Build the argv array by starting with the config for `argv` and substituting in
3939
// script name and args where appropriate.
4040
let script_name = uri_path.to_string();
41-
let args = req.uri().query().unwrap_or_default().replace('&', " ");
42-
let argv = self
43-
.wagi_config
44-
.argv
45-
.clone()
46-
.replace("${SCRIPT_NAME}", &script_name)
47-
.replace("${ARGS}", &args);
41+
42+
let mut args: Vec<String> = Vec::new();
43+
args.push(script_name);
44+
45+
let parsed_url = url::Url::parse(req.uri().to_string().as_str())?;
46+
47+
for (key, value) in parsed_url.query_pairs() {
48+
args.push(key.to_string());
49+
50+
if !value.is_empty() {
51+
args.push(value.to_string());
52+
}
53+
}
4854

4955
let (parts, body) = req.into_parts();
5056

@@ -80,7 +86,7 @@ impl HttpExecutor for WagiHttpExecutor {
8086
.context("The wagi HTTP trigger was configured without the required wasi support")?;
8187

8288
// Set up Wagi environment
83-
wasi_builder.args(argv.split(' '));
89+
wasi_builder.args(args);
8490
wasi_builder.env(headers);
8591
wasi_builder.stdin_pipe(Cursor::new(body));
8692
wasi_builder.stdout(stdout.clone());

0 commit comments

Comments
 (0)