Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 776
Michał Bendowski Avatar asked Oct 08 '12 16:10

Michał Bendowski


2 Answers

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.

like image 164
dm03514 Avatar answered Nov 14 '22 23:11

dm03514


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.

like image 34
Ilya Vassilevsky Avatar answered Nov 14 '22 22:11

Ilya Vassilevsky