OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """This is a simple HTTP server for manually testing exponential | 6 """This is a simple HTTP server for manually testing exponential |
7 back-off functionality in Chrome. | 7 back-off functionality in Chrome. |
8 """ | 8 """ |
9 | 9 |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 self.send_response(200) | 71 self.send_response(200) |
72 self.send_header('Content-Type', 'text/html') | 72 self.send_header('Content-Type', 'text/html') |
73 self.end_headers() | 73 self.end_headers() |
74 self.wfile.write(AJAX_TEST_PAGE % (self.local_ip, | 74 self.wfile.write(AJAX_TEST_PAGE % (self.local_ip, |
75 self.port, | 75 self.port, |
76 self.path[6:])) | 76 self.path[6:])) |
77 return | 77 return |
78 | 78 |
79 params = urlparse.parse_qs(urlparse.urlparse(self.path).query) | 79 params = urlparse.parse_qs(urlparse.urlparse(self.path).query) |
80 | 80 |
81 def SendCustomRetryIfRequested(): | |
82 if params and 'custom-retry-after' in params: | |
83 custom_retry = params['custom-retry-after'][0] | |
84 self.send_header('X-Retry-After', custom_retry) | |
85 | |
86 if not params or not 'code' in params or params['code'][0] == '200': | 81 if not params or not 'code' in params or params['code'][0] == '200': |
87 self.send_response(200) | 82 self.send_response(200) |
88 self.send_header('Content-Type', 'text/plain') | 83 self.send_header('Content-Type', 'text/plain') |
89 SendCustomRetryIfRequested() | |
90 self.end_headers() | 84 self.end_headers() |
91 self.wfile.write('OK') | 85 self.wfile.write('OK') |
92 else: | 86 else: |
93 status_code = int(params['code'][0]) | 87 status_code = int(params['code'][0]) |
94 self.send_response(status_code) | 88 self.send_response(status_code) |
95 SendCustomRetryIfRequested() | |
96 self.end_headers() | 89 self.end_headers() |
97 self.wfile.write('Error %d' % int(status_code)) | 90 self.wfile.write('Error %d' % int(status_code)) |
98 | 91 |
99 | 92 |
100 def main(): | 93 def main(): |
101 if len(sys.argv) != 3: | 94 if len(sys.argv) != 3: |
102 print "Usage: %s LOCAL_IP PORT" % sys.argv[0] | 95 print "Usage: %s LOCAL_IP PORT" % sys.argv[0] |
103 sys.exit(1) | 96 sys.exit(1) |
104 RequestHandler.local_ip = sys.argv[1] | 97 RequestHandler.local_ip = sys.argv[1] |
105 port = int(sys.argv[2]) | 98 port = int(sys.argv[2]) |
106 RequestHandler.port = port | 99 RequestHandler.port = port |
107 print "To stop the server, go to http://localhost:%d/quitquitquit" % port | 100 print "To stop the server, go to http://localhost:%d/quitquitquit" % port |
108 httpd = BaseHTTPServer.HTTPServer(('', port), RequestHandler) | 101 httpd = BaseHTTPServer.HTTPServer(('', port), RequestHandler) |
109 while RequestHandler.keep_running: | 102 while RequestHandler.keep_running: |
110 httpd.handle_request() | 103 httpd.handle_request() |
111 | 104 |
112 | 105 |
113 if __name__ == '__main__': | 106 if __name__ == '__main__': |
114 main() | 107 main() |
OLD | NEW |