Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Forked from ramn/socat_http_echo_server.sh
Last active September 26, 2021 16:06
Show Gist options
  • Save SomajitDey/c4479c034d79b594dae1b564d86e69c7 to your computer and use it in GitHub Desktop.
Save SomajitDey/c4479c034d79b594dae1b564d86e69c7 to your computer and use it in GitHub Desktop.
Socat HTTP echo server
#!/bin/bash
socat -v -T0.05 tcp-l:8081,reuseaddr,fork system:"echo 'HTTP/1.1 200 OK'; echo 'Connection: close'; echo; cat"
#!/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