Skip to content

Instantly share code, notes, and snippets.

@stokito
Created May 8, 2022
Embed
What would you like to do?
CGI script to echo a request

Put the script into /www/cgi-bin/echo.sh and make executable:

chmod +x /www/cgi-bin/echo.sh

Then you can start a webserver e.g.:

busybox httpd -f -vv -p 8080 -h /www

Now you can send requests e.g. with curl or wget:

wget -O - -S -q  http://localhost:8080/cgi-bin/echo.sh
#!/bin/sh
CONTENT=$(cat -)
printf "Content-Length: ${#CONTENT}\r\n"
printf "Content-Type: text/html\r\n"
printf "REQUEST_METHOD: $REQUEST_METHOD\r\n"
printf "CONTENT_TYPE: $CONTENT_TYPE\r\n"
printf "CONTENT_LENGTH: $CONTENT_LENGTH\r\n"
printf "\r\n"
printf "$CONTENT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment