""" PythonHTTPServer.py - simple Web Server using BaseHTTPServer module in Python """ from BaseHTTPServer import HTTPServer from BaseHTTPServer import BaseHTTPRequestHandler import string """ class ourRequestHandler - deals with requests of the Web Server """ class ourRequestHandler(BaseHTTPRequestHandler): """ do_GET helps with GET requests """ def do_GET(self): # always return 200 = OK self.ourPrintCustomHTTPResponse(200) # HTML output self.wfile.write("
") self.wfile.write("Welcome to our simple local Python Web Server.
") self.wfile.write("Method GET string: " + self.path + "
") # ... browser headers ... self.ourPrintBrowserHeaders() # ... and finish up self.wfile.write("
") """ do_POST helps with POST requests """ def do_POST(self): # always return 200 = OK self.ourPrintCustomHTTPResponse(200) # HTML output self.wfile.write("") self.wfile.write("") self.ourPrintBrowserHeaders() self.wfile.write("Method Post Data:
") # ... post length logic ... if self.headers.dict.has_key("content-length"): # ... string to int ... our_content_length = string.atoi(self.headers.dict["content-length"]) # ... read from client ... our_raw_post_data = self.rfile.read(our_content_length) self.wfile.write(our_raw_post_data) # ... and finish up self.wfile.write("
") """ ourPrintBrowserHeaders prints HTTP headers """ def ourPrintBrowserHeaders(self): # navigate dictionary header name/value pairs self.wfile.write("Headers: