Last active
January 26, 2019 19:11
-
-
Save felixSchl/ce6143c06d3a6ff360d6397c8f71349a to your computer and use it in GitHub Desktop.
Simple netcat HTTP server (without -c/-e)
This file contains 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 | |
set -e | |
function run_handler { | |
: # whatever | |
} | |
while :; do | |
rm -f pipe | |
mkfifo pipe | |
cat pipe | nc -l 8888 | ( | |
set +e | |
read | |
echo -n 'running handler... ' | |
result=$(run_handler 2>&1) | |
if [[ "$?" -eq 0 ]]; then | |
echo 'OK' | |
{ | |
echo 'HTTP/1.1 200 OK' | |
echo 'Connection: Close' | |
} &> pipe | |
else | |
echo 'FAIL' | |
echo "$result" | |
{ | |
echo 'HTTP/1.1 500 Internal Server Error' | |
echo 'Connection: Close' | |
} &> pipe | |
fi | |
) | |
done | |
# vim: set noet: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment