Last active
September 26, 2023 12:22
-
-
Save ramn/cfe0021b48c3e5d1f3f3 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_PEERPORT" | |
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
SOCAT_PEER_PORT should be SOCAT_PEERPORT