OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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/FTP/SYNC/TCP/UDP/ server used for testing Chrome. | 6 """This is a simple HTTP/FTP/SYNC/TCP/UDP/ server used for testing Chrome. |
7 | 7 |
8 It supports several test URLs, as specified by the handlers in TestPageHandler. | 8 It supports several test URLs, as specified by the handlers in TestPageHandler. |
9 By default, it listens on an ephemeral port and sends the port number back to | 9 By default, it listens on an ephemeral port and sends the port number back to |
10 the originating process over a pipe. The originating process can specify an | 10 the originating process over a pipe. The originating process can specify an |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 put_handlers): | 291 put_handlers): |
292 self._connect_handlers = connect_handlers | 292 self._connect_handlers = connect_handlers |
293 self._get_handlers = get_handlers | 293 self._get_handlers = get_handlers |
294 self._head_handlers = head_handlers | 294 self._head_handlers = head_handlers |
295 self._post_handlers = post_handlers | 295 self._post_handlers = post_handlers |
296 self._put_handlers = put_handlers | 296 self._put_handlers = put_handlers |
297 BaseHTTPServer.BaseHTTPRequestHandler.__init__( | 297 BaseHTTPServer.BaseHTTPRequestHandler.__init__( |
298 self, request, client_address, socket_server) | 298 self, request, client_address, socket_server) |
299 | 299 |
300 def log_request(self, *args, **kwargs): | 300 def log_request(self, *args, **kwargs): |
301 print '%s %s %s' % (self.path, args, kwargs) | |
mmenke
2012/02/01 19:08:07
You only added this for your own debugging, right?
James Simonsen
2012/02/07 00:01:37
Oops. Yeah.
| |
301 # Disable request logging to declutter test log output. | 302 # Disable request logging to declutter test log output. |
302 pass | 303 pass |
303 | 304 |
304 def _ShouldHandleRequest(self, handler_name): | 305 def _ShouldHandleRequest(self, handler_name): |
305 """Determines if the path can be handled by the handler. | 306 """Determines if the path can be handled by the handler. |
306 | 307 |
307 We consider a handler valid if the path begins with the | 308 We consider a handler valid if the path begins with the |
308 handler name. It can optionally be followed by "?*", "/*". | 309 handler name. It can optionally be followed by "?*", "/*". |
309 """ | 310 """ |
310 | 311 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 self.AuthDigestHandler, | 372 self.AuthDigestHandler, |
372 self.SlowServerHandler, | 373 self.SlowServerHandler, |
373 self.ChunkedServerHandler, | 374 self.ChunkedServerHandler, |
374 self.ContentTypeHandler, | 375 self.ContentTypeHandler, |
375 self.NoContentHandler, | 376 self.NoContentHandler, |
376 self.ServerRedirectHandler, | 377 self.ServerRedirectHandler, |
377 self.ClientRedirectHandler, | 378 self.ClientRedirectHandler, |
378 self.MultipartHandler, | 379 self.MultipartHandler, |
379 self.MultipartSlowHandler, | 380 self.MultipartSlowHandler, |
380 self.GetSSLSessionCacheHandler, | 381 self.GetSSLSessionCacheHandler, |
382 self.CloseSocketHandler, | |
381 self.DefaultResponseHandler] | 383 self.DefaultResponseHandler] |
382 post_handlers = [ | 384 post_handlers = [ |
383 self.EchoTitleHandler, | 385 self.EchoTitleHandler, |
384 self.EchoHandler, | 386 self.EchoHandler, |
385 self.DeviceManagementHandler, | 387 self.DeviceManagementHandler, |
386 self.PostOnlyFileHandler] + get_handlers | 388 self.PostOnlyFileHandler] + get_handlers |
387 put_handlers = [ | 389 put_handlers = [ |
388 self.EchoTitleHandler, | 390 self.EchoTitleHandler, |
389 self.EchoHandler] + get_handlers | 391 self.EchoHandler] + get_handlers |
390 head_handlers = [ | 392 head_handlers = [ |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
919 if not self.path.startswith(prefix): | 921 if not self.path.startswith(prefix): |
920 return False | 922 return False |
921 self.ReadRequestBody() | 923 self.ReadRequestBody() |
922 return self._FileHandlerHelper(prefix) | 924 return self._FileHandlerHelper(prefix) |
923 | 925 |
924 def _FileHandlerHelper(self, prefix): | 926 def _FileHandlerHelper(self, prefix): |
925 _, _, url_path, _, query, _ = urlparse.urlparse(self.path) | 927 _, _, url_path, _, query, _ = urlparse.urlparse(self.path) |
926 sub_path = url_path[len(prefix):] | 928 sub_path = url_path[len(prefix):] |
927 entries = sub_path.split('/') | 929 entries = sub_path.split('/') |
928 file_path = os.path.join(self.server.data_dir, *entries) | 930 file_path = os.path.join(self.server.data_dir, *entries) |
931 print 'file_path %s' % file_path | |
mmenke
2012/02/01 19:08:07
This was just for your own debugging, right?
James Simonsen
2012/02/07 00:01:37
Done.
| |
929 if os.path.isdir(file_path): | 932 if os.path.isdir(file_path): |
930 file_path = os.path.join(file_path, 'index.html') | 933 file_path = os.path.join(file_path, 'index.html') |
931 | 934 |
932 if not os.path.isfile(file_path): | 935 if not os.path.isfile(file_path): |
933 print "File not found " + sub_path + " full path:" + file_path | 936 print "File not found " + sub_path + " full path:" + file_path |
934 self.send_error(404) | 937 self.send_error(404) |
935 return True | 938 return True |
936 | 939 |
937 f = open(file_path, "rb") | 940 f = open(file_path, "rb") |
938 data = f.read() | 941 data = f.read() |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1420 self.send_header('Content-Type', 'text/plain') | 1423 self.send_header('Content-Type', 'text/plain') |
1421 self.end_headers() | 1424 self.end_headers() |
1422 try: | 1425 try: |
1423 for (action, sessionID) in self.server.session_cache.log: | 1426 for (action, sessionID) in self.server.session_cache.log: |
1424 self.wfile.write('%s\t%s\n' % (action, sessionID.encode('hex'))) | 1427 self.wfile.write('%s\t%s\n' % (action, sessionID.encode('hex'))) |
1425 except AttributeError, e: | 1428 except AttributeError, e: |
1426 self.wfile.write('Pass --https-record-resume in order to use' + | 1429 self.wfile.write('Pass --https-record-resume in order to use' + |
1427 ' this request') | 1430 ' this request') |
1428 return True | 1431 return True |
1429 | 1432 |
1433 def CloseSocketHandler(self): | |
1434 """Closes the socket without sending anything.""" | |
1435 | |
1436 if not self._ShouldHandleRequest('/close-socket'): | |
1437 return False | |
1438 | |
1439 self.wfile.close() | |
1440 return True | |
1441 | |
1430 def DefaultResponseHandler(self): | 1442 def DefaultResponseHandler(self): |
1431 """This is the catch-all response handler for requests that aren't handled | 1443 """This is the catch-all response handler for requests that aren't handled |
1432 by one of the special handlers above. | 1444 by one of the special handlers above. |
1433 Note that we specify the content-length as without it the https connection | 1445 Note that we specify the content-length as without it the https connection |
1434 is not closed properly (and the browser keeps expecting data).""" | 1446 is not closed properly (and the browser keeps expecting data).""" |
1435 | 1447 |
1436 contents = "Default response given for path: " + self.path | 1448 contents = "Default response given for path: " + self.path |
1437 self.send_response(200) | 1449 self.send_response(200) |
1438 self.send_header('Content-Type', 'text/html') | 1450 self.send_header('Content-Type', 'text/html') |
1439 self.send_header('Content-Length', len(contents)) | 1451 self.send_header('Content-Length', len(contents)) |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2005 'random key if none is specified on the command ' | 2017 'random key if none is specified on the command ' |
2006 'line.') | 2018 'line.') |
2007 option_parser.add_option('', '--policy-user', default='user@example.com', | 2019 option_parser.add_option('', '--policy-user', default='user@example.com', |
2008 dest='policy_user', | 2020 dest='policy_user', |
2009 help='Specify the user name the server should ' | 2021 help='Specify the user name the server should ' |
2010 'report back to the client as the user owning the ' | 2022 'report back to the client as the user owning the ' |
2011 'token used for making the policy request.') | 2023 'token used for making the policy request.') |
2012 options, args = option_parser.parse_args() | 2024 options, args = option_parser.parse_args() |
2013 | 2025 |
2014 sys.exit(main(options, args)) | 2026 sys.exit(main(options, args)) |
OLD | NEW |