The following is what I came up with -- great for testing.
# USAGE:
# python ./hello.py free beer
import SimpleHTTPServer
import StringIO
import SocketServer
import sys
PORT = 8000
class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
MESSAGE = ' '.join(sys.argv[1:])
def send_head(self):
self.send_response(200)
self.send_header("Content-type", 'text/plain')
self.end_headers()
return StringIO.StringIO(self.MESSAGE)
httpd = SocketServer.TCPServer(("", PORT), MyHandler)
print "serving at port", PORT
httpd.serve_forever()
No comments:
Post a Comment