Michał Bendowski
Michał Bendowski

Reputation: 2791

Is there a ready-made HTTP server for debugging purposes?

Today I found myself needing a simple HTTP server that would log/print out everything it knows about the request and respond with some dummy reply (for debugging). Surprisingly enough, I couldn't find any read to use tool for that - am I missing something?

Python's SimpleHTTPServer module looks promising, maybe there is a really quick way to just dump the whole request using it?

I need it to run locally.

Upvotes: 9

Views: 9354

Answers (5)

somecoder
somecoder

Reputation: 83

If you have nodejs installed:

npx dummy-http-server

This will open a simple http server which listens on port 8080 and prints the request to STDOUT.

If you need advanced options:

npx dummy-http-server --help

Upvotes: 0

StephenHealey86
StephenHealey86

Reputation: 81

Hi take a look at ReturnToSender on github, its a mock http server that runs locally. Not web hosted. Responds to http client with your mock data and displays client request details.

https://github.com/stephenhealey86/ReturnToSender

Supports GET, POST, PUT, PATCH, DELETE request types and JSON, TEXT, JavaScript, XML, HTML content types.

Upvotes: 0

Petri
Petri

Reputation: 5006

Turq works well for this kind of purpose. It is written in Python, simple to use yet extensive, flexible and even has a GUI. Developers of Turq describe it thus:

Turq is a small HTTP server that can be scripted in a Python-based language. Use it to set up mock HTTP resources that respond with the status, headers, and body of your choosing. Turq is designed for quick interactive testing, but can be used in automated scenarios as well.

It also has good documentation.

Caveat: While Turq is perfectly useful, its author has stopped maintaining it, recommending mitmproxy instead; mitmproxy has a Python API too.

Upvotes: 0

Ilya Vassilevsky
Ilya Vassilevsky

Reputation: 1001

ruby -r sinatra -e "get('/') { puts params.inspect }"

Documentation: http://www.sinatrarb.com

Ruby is simple and flexible and it allows you to mock any reply quickly.

Upvotes: 6

dm03514
dm03514

Reputation: 55972

From some quick searches on google it looks like the easiest way to do this would be to sublcass SimpleHttpServer and log whatever it is you want to see.

This looks to be very easy

class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):

    def do_GET(self):
        logging.error(self.headers)
        # whatever else you would like to log here
        SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

Handler = ServerHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()

Additionally you can have your do_GET and do_POST return whatever 'dummy' reply you want.

Upvotes: 8

Related Questions