Last active
June 3, 2020 11:37
-
-
Save amcginlay/731d2f2fe77fc9cb56509502bb17ffb4 to your computer and use it in GitHub Desktop.
socat server user data - example request: curl localhost/3
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
# inspired by https://jameshfisher.com/2018/12/31/how-to-make-a-webserver-with-netcat-nc/ | |
#!/bin/bash | |
yum install -y socat | |
socat TCP4-LISTEN:${PORT:-80},fork SYSTEM:' \ | |
read -r line \ | |
read -r _ workload _ <<< "$line" \ | |
workload=${workload:1} | |
[ ! -z "$workload" ] && timeout $workload yes > /dev/null \ | |
echo HTTP/1.0 200 \ | |
echo Content-Type\: text/plain \ | |
echo \ | |
echo Response from $(hostname) with ${workload:-0} secs workload at $(date '+%s.%N')' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment