Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@GuillermoBlasco
Created August 25, 2013 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuillermoBlasco/6332798 to your computer and use it in GitHub Desktop.
Save GuillermoBlasco/6332798 to your computer and use it in GitHub Desktop.
import time
import BaseHTTPServer
import cgi
HOST_NAME = 'localhost'
PORT_NUMBER = 9200
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_HEAD(s):
s.send_response(200)
s.send_header("Content-type", "text/html")
s.end_headers()
def do_GET(s):
"""Respond to a GET request."""
s.send_response(200)
s.send_header("Content-type", "application/json")
s.end_headers()
print "wrting output for " + str(s)
s.wfile.write("[]")
def do_POST(s):
# Parse the form data posted
form = cgi.FieldStorage(
fp=s.rfile,
headers=s.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':s.headers['Content-Type'],
})
"""Respond to a GET request."""
s.send_response(200)
s.send_header("Content-type", "application/json")
s.end_headers()
s.wfile.write("[{'p':'false'},{'k':'true'}]")
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment