-
-
Save jiaoyk/7c57af079c3cfa3809f214c8529e6d1c to your computer and use it in GitHub Desktop.
Socat HTTP echo server
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 | |
socat -v -T0.05 tcp-l:8081,reuseaddr,fork system:"echo 'HTTP/1.1 200 OK'; echo 'Connection: close'; echo; cat" |
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 | |
handle() { | |
echo 'HTTP/1.0 200 OK' | |
echo 'Content-Type: text/plain' | |
echo "Date: $(date)" | |
echo "Server: $SOCAT_SOCKADDR:$SOCAT_SOCKPORT" | |
echo "Client: $SOCAT_PEERADDR:$SOCAT_PEER_PORT" | |
echo 'Connection: close' | |
echo | |
cat | |
} | |
case $1 in | |
"bind") | |
socat -T0.05 -v tcp-l:8081,reuseaddr,fork,crlf system:". $0 && handle" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment