I would use a Bash script that invokes
netcat once for each response type, with appropriate input to generate each different kind of response code. I would pipe this though
grep to check for the correct response and echo out a message on
STDERR if it's not correct.
This should be relatively easy for the 2xx, 3xx and 4xx ranges assuming there exist URLs on your server that actually generate each different response code. The 5xx ranges refer to server-side errors, so to deliberately invoke them you will need to set up specific URLs on your server that cause each error. The 1xx range are probably best tested using a more complete HTTP client such as
There is most likely more than one way to solve this problem.
There's a nasty bug in some version of netcat that means that it exits as soon as it has finished reading from STDIN. Also, the man pages shipped with this buggy version include an example that doesn't work. The workaround is the
-q <number> option which specifies a number of seconds to hang around waiting for an answer before quitting.
echo -ne "GET / HTTP/1.1\nHost: example.com\n\n" | nc -q 1 example.com 80 | grep -q "HTTP/1.1 301" || echo "HTTP 302 test failed!" >&2