deislabs / wagi

Write HTTP handlers in WebAssembly with a minimal amount of work
Apache License 2.0
884 stars 45 forks source link

Issue with Passing Multiple Command Line Arguments to WAGI Handler via URL #192

Open FerrazArthur opened 11 months ago

FerrazArthur commented 11 months ago

I'm currently working with the WAGI interface and I'm facing an issue when trying to pass multiple arguments to a C to WebAssembly (WASM) handler. The handler code uses argv to iterate through arguments. While I've been successful in passing individual arguments like '--tamanho=10000' or '--help' with QUERY_STRING, I'm struggling to pass multiple arguments.

Valid Arguments:

--tamanho=<integer>: Specifies the number of elements to be sorted.
--imprime: Enables the printing of elements before and after sorting.
--help: Prints the help information.

Problem: I need to pass multiple arguments simultaneously, such as --tamanho=20 and --imprime, but I haven't been able to do this successfully.

Attempts: I've tried various ways to pass these multiple arguments, but none of them have worked:

curl http://127.0.0.1:3000/quicksort?--tamanho=20+--imprime
curl http://127.0.0.1:3000/quicksort?--tamanho=20\+--imprime
curl http://127.0.0.1:3000/quicksort?"--tamanho=20\+--imprime"
curl "http://127.0.0.1:3000/quicksort?--tamanho=20\+--imprime"
curl http://127.0.0.1:3000/quicksort?param1=--tamanho=20&param2=--imprime
curl http://127.0.0.1:3000/quicksort?param1=--tamanho=20\&param2=--imprime
curl http://127.0.0.1:3000/quicksort?--tamanho=1000%20--imprime
curl http://127.0.0.1:3000/quicksort?--tamanho=1000\%20--imprime
curl http://127.0.0.1:3000/quicksort?--tamanho=1000\ --imprime

Expected Behavior: I should be able to pass multiple arguments, such as --tamanho=20 and --imprime, to the handler via the URL, and the handler should be able to correctly interpret and process these arguments.

Actual Behavior: None of the above methods have successfully allowed me to pass multiple arguments to the WAGI handler in such a way that the argv[] identify them individually. Please advise on the correct way to pass multiple arguments in this scenario or provide a solution to this issue. In order to bypass this, i changed the design of the arguments string, but thats not ideal for my use case.

Thank you for your assistance in resolving this problem.

itowlson commented 11 months ago

Could you try please:

curl localhost:3000/?--tamanho=20\&--imprime

With this URL, for me the argv contains

/
--tamanho=20
--imprime
FerrazArthur commented 11 months ago

I thought i had tried it already, but it actually worked this time! thank you for the help, really appreciate.