Created
July 28, 2025 18:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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