Created
January 28, 2015 00:32
-
-
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.
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
#!/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