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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With