I need a gratis tool for Windows which opens a specific TCP port (configurable, e.g. Port 80) and returns an HTTP error code (configurable, e.g. HTTP 503).

It must have a command line version. It doesn't need a UI, but may also have a UI, e.g. if no parameters were given. It shall not be a Browser extension (Chrome, Firefox).

The tool should be as simple as possible. I don't really want a full web proxy with REST support and tons of configuration. This must be BDU (brain dead user) compatible :-)

While that might be almost trivial to implement myself, I'd prefer not to get a programming language suggestion. I don't want to maintain this thing.

What would I use this for?

  1. Testing purposes.

    Some of our applications use HTTP. I want to see how they behave if the service is not available etc.

  2. Speeding up applications.

    Some applications are trying to connect to the Internet, but our IT department has blocked the port by a Firewall. Therefore, those applications will never get an answer. Typically they will retry 3 times and wait up to 1 minute per try. This gives a 3 minute delay.

    With the tool, I can change the hosts file to point to my local machine. If the tool returns a HTTP404, the application will likely stop after 1 try and also get an answer immediately, so there's no need to wait.

1 Answer 1


Mock Server seems to be able to do what you need, but you will need to dig a little bit to get it running. Here is the git repository.

For any system you integrate with via HTTP or HTTPS MockServer can be used as:

a mock configured to return specific responses for different requests a proxy recording and optionally modifying requests and responses both a proxy for some requests and a mock for other requests at the same time When MockServer receives a request it matches the request against active expectations that have been configured. Then, if no matches are found, it proxies the request if appropriate; otherwise a 404 is returned.

For each request received the following steps happen:

find matching expectation and perform action if no matching expectation proxy request if not a proxy request return 404

Much easier in my opinion is the http-server-mock python library, which yes will reguire a small bit of code from you, but otherwise will get you there almost immediately:

from http_server_mock import HttpServerMock
import requests
app = HttpServerMock(__name__)

@app.route("/", methods=["GET"])
def index():
    return "Hello world"

with app.run("localhost", 5000):
    r = requests.get("http://localhost:5000/")
    # r.status_code == 200               # <<<------ pretty sure this is the magic you need
    # r.text == "Hello world"

Digging into the Flask documentation (on which http-server-mock is based), make_response seems how you set status codes in the index function:

def index():
    response = make_response(render_template('not_found.html'), 404)
    return response

And finally, I found httpstat.us which is an online service which simply returns different http status codes, so maybe this can help your use case if you don't need a local server which returns the codes.

  • httpstat.us requires the use of a specific path which I can't change. Commented Jan 17, 2023 at 10:56
  • r.status_code == 200 is a comparison to the result what index() returned. What I need is a setter inside index(). Commented Jan 17, 2023 at 10:58
  • @ThomasWeller Regarding httpstat.us, maybe a proxy can help (not sure if this makes things easier than other options though).
    – kutschkem
    Commented Jan 17, 2023 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.