Tag Mock Server

Quick Mock Server

Are you in a need of a quick mock server? One simple solution for Linux/Mac/BSD users is to employ an existing tool, nc. It exists in most distros and it’s very easy to use. #!/bin/bash if [ "$#" -ne "1" ]; then echo "usage: ./mock_server.sh <port>" exit 1 fi trap "{ exit 0; }" SIGINT SIGTERM SIGKILL PORT="$1" function make_response() { read -r response echo -e "HTTP/1.1 200 OK\r\n\r\n${response}" } while true ; do dd if=/dev/zero count=10000 make_response | nc -l "$PORT" done Save this in a file called mock_server.