A different kind of Hello World

Following the last post, here’s a new Hello World:

Hello World

The party responsible for the above:

# File: simplehttp.py

import SocketServer

PORT = 80

PAGE="""<html><head><title>Hello World!</title></head>
<body>Hello World! You are reading a page served by a local server!<br/>
Your request headers were: <br/>
<pre>%s</pre></body></html>"""

class HTTPRespHandler(SocketServer.StreamRequestHandler):
    def handle(self):
        print "connection from", self.client_address
        resp = "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" + (PAGE % self.rfile.read(300))
        self.wfile.write(resp)

if __name__ == '__main__':
    server = SocketServer.TCPServer(("0.0.0.0", PORT), HTTPRespHandler)
    print "listening on port", PORT
    try:
        server.serve_forever()
    except:
        server.server_close()

Points of interest: