Skip to content

Instantly share code, notes, and snippets.

@favila
Created January 28, 2015 00:32
Show Gist options
  • Save favila/9db643489e57bbc65c1c to your computer and use it in GitHub Desktop.
Save favila/9db643489e57bbc65c1c to your computer and use it in GitHub Desktop.
Netcat-based logging http server for debugging. Writes raw http requests to individual files and replies with a 204.
#!/bin/sh
# A netcat-based logging http server for debugging.
#
# Writes raw http requests to individual files and replies with a 204.
PORT=${1-"8085"}
OUTFILEPREFIX=${2-"request"}
REPLY='HTTP/1.1 204 NO CONTENT\r\nconnection: close\r\n\r\n'
OUTFILE=''
cleanup () {
if [ -n "$OUTFILE" -a -f "$OUTFILE" -a ! -s "$OUTFILE" ]; then
rm "$OUTFILE";
fi
exit 0;
}
trap cleanup HUP INT TERM QUIT
while true; do
OUTFILE="$OUTFILEPREFIX-$(date +%0s).bin"
echo "> $OUTFILE"
echo -n "$REPLY" | nc -v -l -p $PORT > "$OUTFILE";
OUTFILE=''
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment