Created
June 24, 2014 19:35
-
-
Save ConnorDoyle/7e0790e24085d535c871 to your computer and use it in GitHub Desktop.
A web service, made to fail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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