aksdb / caddy-cgi

Common Gateway Interface plugin for the Caddy HTTP server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with empty POST_DATA with Content-Type "application/x-www-form-urlencoded"

DblK opened this issue · comments

Hi,

I have a cgi call with method POST and content-type application/x-www-form-urlencoded.
The payload is two variables: sessionid and command.
sessionid is a uuid and command is %2Fusr%2Flibexec%2Fopkg-call%20list-available

I wrote a bash script to display everything and the HTTP_CONTENT_LENGTH variable has value 96 (which is correct) but the POST_DATA variable is not set.

Take from your documentation I built the following command:

wget -O - -q --post-data="sessionid=999999f9999998877665544332211007&command=%2Fusr%2Flibexec%2Fopkg-call%20list-available" http://192.168.1.2:8080/show/weekly?mode=summary

Inside my script I put printf "POST_DATA [%s]\n" $POST_DATA but it's always empty.

When putting inspect in the Placeholders I can not see http.request.body...

Could you help me to get the form data in my bash script?
This is the missing part to make OpenWrt LuCI work with Caddy 🙏

Caddy built from official website and here is the info:

caddy --version
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

Never mind, I did not see a part of the bash script you wrote in the documentation.
I was missing :

if [ "POST" = "$REQUEST_METHOD" -a -n "$CONTENT_LENGTH" ]; then
  read -n "$CONTENT_LENGTH" POST_DATA
fi

This allows to have the actual body into $POST_DATA.