Last active
December 26, 2015 19:09
-
-
Save jctanner/7199435 to your computer and use it in GitHub Desktop.
Random Exit Code httpd server
This file contains hidden or 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 BaseHTTPServer | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
from StringIO import StringIO | |
import random | |
class RandomExitCodes(SimpleHTTPRequestHandler): | |
def list_directory(self, path): | |
f = StringIO() | |
f.write("hello world\n") | |
f.seek(0) | |
x = [200, 300, 401, 500] | |
random.shuffle(x) | |
print x | |
self.send_response(x[0]) | |
self.send_header("Content-type", "text/html") | |
self.end_headers() | |
return f | |
#HandlerClass = SimpleHTTPRequestHandler | |
HandlerClass = RandomExitCodes | |
ServerClass = BaseHTTPServer.HTTPServer | |
Protocol = "HTTP/1.0" | |
server_address = ('el6.lab.net', 80) | |
HandlerClass.protocol_version = Protocol | |
httpd = ServerClass(server_address, HandlerClass) | |
sa = httpd.socket.getsockname() | |
print "Serving HTTP on", sa[0], "port", sa[1], "..." | |
#import epdb; epdb.st() | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment