Skip to content

Instantly share code, notes, and snippets.

@distgr
Created July 28, 2025 18:59
Show Gist options
  • Select an option

  • Save distgr/c2f01de586628a4d2850b0fa38e68d28 to your computer and use it in GitHub Desktop.

Select an option

Save distgr/c2f01de586628a4d2850b0fa38e68d28 to your computer and use it in GitHub Desktop.
Minimal Bash web server using socat to handle POST requests as www-data.
#!/bin/bash
handle_request() {
# extract www-data from POST request
read method
while read header; do
[[ "$header" == $'\r' ]] && break
done
if [[ "$method" =~ POST ]]; then
read -n "$CONTENT_LENGTH" post_data
echo "POST DATA: $post_data" >> /tmp/post.log
fi
echo -ne "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nHello from Bash"
}
export -f handle_request
# run socat to listen on 8080
sudo -u www-data socat TCP-LISTEN:8080,reuseaddr,fork SYSTEM:"bash -c handle_request"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment