Skip to content

Instantly share code, notes, and snippets.

@ConnorDoyle
Created June 24, 2014 19:35
Show Gist options
  • Save ConnorDoyle/7e0790e24085d535c871 to your computer and use it in GitHub Desktop.
Save ConnorDoyle/7e0790e24085d535c871 to your computer and use it in GitHub Desktop.
A web service, made to fail.
import sys
import SimpleHTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
import SocketServer
import urlparse
PORT = int(sys.argv[1])
healthy = True
class ToggleHandler(BaseHTTPRequestHandler):
def do_GET(self):
global healthy
parsed_path = urlparse.urlparse(self.path)
print "GET: [%s]\n" % parsed_path.path
if parsed_path.path == "/toggle":
healthy = not healthy
print "Setting health to [%s]\n" % healthy
self.send_response(200)
message = "Set health to [%s]" % healthy
elif healthy:
self.send_response(200)
message = "OK"
else:
self.send_response(410)
message = "Gone"
self.end_headers()
self.wfile.write(message)
return
httpd = SocketServer.TCPServer(("", PORT), ToggleHandler)
print "Bound to port [%s]" % PORT
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment