1 #!/usr/bin/python2.4 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 """This is a simple HTTP server for manually testing exponential 7 back-off functionality in Chrome. 8 """ 9 10 11 import BaseHTTPServer 12 import sys 13 import urlparse 14 15 16 class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): 17 keep_running = True 18 19 def do_GET(self): 20 if self.path == '/quitquitquit': 21 self.send_response(200) 22 self.send_header('Content-Type', 'text/plain') 23 self.end_headers() 24 self.wfile.write('QUITTING') 25 RequestHandler.keep_running = False 26 return 27 28 params = urlparse.parse_qs(urlparse.urlparse(self.path).query) 29 30 if not params or not 'code' in params or params['code'][0] == '200': 31 self.send_response(200) 32 self.send_header('Content-Type', 'text/plain') 33 self.end_headers() 34 self.wfile.write('OK') 35 else: 36 self.send_error(int(params['code'][0])) 37 38 39 def main(): 40 if len(sys.argv) != 2: 41 print "Usage: %s PORT" % sys.argv[0] 42 sys.exit(1) 43 port = int(sys.argv[1]) 44 print "To stop the server, go to http://localhost:%d/quitquitquit" % port 45 httpd = BaseHTTPServer.HTTPServer(('', port), RequestHandler) 46 while RequestHandler.keep_running: 47 httpd.handle_request() 48 49 50 if __name__ == '__main__': 51 main() 52