| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 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 used for testing Chrome. | 6 """This is a simple HTTP 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 self.CacheMustRevalidateMaxAgeHandler, | 274 self.CacheMustRevalidateMaxAgeHandler, |
| 275 self.CacheNoStoreHandler, | 275 self.CacheNoStoreHandler, |
| 276 self.CacheNoStoreMaxAgeHandler, | 276 self.CacheNoStoreMaxAgeHandler, |
| 277 self.CacheNoTransformHandler, | 277 self.CacheNoTransformHandler, |
| 278 self.DownloadHandler, | 278 self.DownloadHandler, |
| 279 self.DownloadFinishHandler, | 279 self.DownloadFinishHandler, |
| 280 self.EchoHeader, | 280 self.EchoHeader, |
| 281 self.EchoHeaderOverride, | 281 self.EchoHeaderOverride, |
| 282 self.EchoAllHandler, | 282 self.EchoAllHandler, |
| 283 self.FileHandler, | 283 self.FileHandler, |
| 284 self.RealFileWithCommonHeaderHandler, | |
| 285 self.RealBZ2FileWithCommonHeaderHandler, | |
| 286 self.SetCookieHandler, | 284 self.SetCookieHandler, |
| 287 self.AuthBasicHandler, | 285 self.AuthBasicHandler, |
| 288 self.AuthDigestHandler, | 286 self.AuthDigestHandler, |
| 289 self.SlowServerHandler, | 287 self.SlowServerHandler, |
| 290 self.ContentTypeHandler, | 288 self.ContentTypeHandler, |
| 291 self.ServerRedirectHandler, | 289 self.ServerRedirectHandler, |
| 292 self.ClientRedirectHandler, | 290 self.ClientRedirectHandler, |
| 293 self.MultipartHandler, | 291 self.MultipartHandler, |
| 294 self.DefaultResponseHandler] | 292 self.DefaultResponseHandler] |
| 295 post_handlers = [ | 293 post_handlers = [ |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 self.send_header('Content-type', self.GetMIMETypeFromName(file_path)) | 820 self.send_header('Content-type', self.GetMIMETypeFromName(file_path)) |
| 823 self.send_header('Accept-Ranges', 'bytes') | 821 self.send_header('Accept-Ranges', 'bytes') |
| 824 self.send_header('Content-Length', len(data)) | 822 self.send_header('Content-Length', len(data)) |
| 825 self.send_header('ETag', '\'' + file_path + '\'') | 823 self.send_header('ETag', '\'' + file_path + '\'') |
| 826 self.end_headers() | 824 self.end_headers() |
| 827 | 825 |
| 828 self.wfile.write(data) | 826 self.wfile.write(data) |
| 829 | 827 |
| 830 return True | 828 return True |
| 831 | 829 |
| 832 def RealFileWithCommonHeaderHandler(self): | |
| 833 """This handler sends the contents of the requested file without the pseudo | |
| 834 http head!""" | |
| 835 | |
| 836 prefix='/realfiles/' | |
| 837 if not self.path.startswith(prefix): | |
| 838 return False | |
| 839 | |
| 840 file = self.path[len(prefix):] | |
| 841 path = os.path.join(self.server.data_dir, file) | |
| 842 | |
| 843 try: | |
| 844 f = open(path, "rb") | |
| 845 data = f.read() | |
| 846 f.close() | |
| 847 | |
| 848 # just simply set the MIME as octal stream | |
| 849 self.send_response(200) | |
| 850 self.send_header('Content-type', 'application/octet-stream') | |
| 851 self.end_headers() | |
| 852 | |
| 853 self.wfile.write(data) | |
| 854 except: | |
| 855 self.send_error(404) | |
| 856 | |
| 857 return True | |
| 858 | |
| 859 def RealBZ2FileWithCommonHeaderHandler(self): | |
| 860 """This handler sends the bzip2 contents of the requested file with | |
| 861 corresponding Content-Encoding field in http head!""" | |
| 862 | |
| 863 prefix='/realbz2files/' | |
| 864 if not self.path.startswith(prefix): | |
| 865 return False | |
| 866 | |
| 867 parts = self.path.split('?') | |
| 868 file = parts[0][len(prefix):] | |
| 869 path = os.path.join(self.server.data_dir, file) + '.bz2' | |
| 870 | |
| 871 if len(parts) > 1: | |
| 872 options = parts[1] | |
| 873 else: | |
| 874 options = '' | |
| 875 | |
| 876 try: | |
| 877 self.send_response(200) | |
| 878 accept_encoding = self.headers.get("Accept-Encoding") | |
| 879 if accept_encoding.find("bzip2") != -1: | |
| 880 f = open(path, "rb") | |
| 881 data = f.read() | |
| 882 f.close() | |
| 883 self.send_header('Content-Encoding', 'bzip2') | |
| 884 self.send_header('Content-type', 'application/x-bzip2') | |
| 885 self.end_headers() | |
| 886 if options == 'incremental-header': | |
| 887 self.wfile.write(data[:1]) | |
| 888 self.wfile.flush() | |
| 889 time.sleep(1.0) | |
| 890 self.wfile.write(data[1:]) | |
| 891 else: | |
| 892 self.wfile.write(data) | |
| 893 else: | |
| 894 """client do not support bzip2 format, send pseudo content | |
| 895 """ | |
| 896 self.send_header('Content-type', 'text/html; charset=ISO-8859-1') | |
| 897 self.end_headers() | |
| 898 self.wfile.write("you do not support bzip2 encoding") | |
| 899 except: | |
| 900 self.send_error(404) | |
| 901 | |
| 902 return True | |
| 903 | |
| 904 def SetCookieHandler(self): | 830 def SetCookieHandler(self): |
| 905 """This handler just sets a cookie, for testing cookie handling.""" | 831 """This handler just sets a cookie, for testing cookie handling.""" |
| 906 | 832 |
| 907 if not self._ShouldHandleRequest("/set-cookie"): | 833 if not self._ShouldHandleRequest("/set-cookie"): |
| 908 return False | 834 return False |
| 909 | 835 |
| 910 query_char = self.path.find('?') | 836 query_char = self.path.find('?') |
| 911 if query_char != -1: | 837 if query_char != -1: |
| 912 cookie_values = self.path[query_char + 1:].split('&') | 838 cookie_values = self.path[query_char + 1:].split('&') |
| 913 else: | 839 else: |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 option_parser.add_option('', '--policy-cert-chain', action='append', | 1456 option_parser.add_option('', '--policy-cert-chain', action='append', |
| 1531 help='Specify a path to a certificate file to sign ' | 1457 help='Specify a path to a certificate file to sign ' |
| 1532 'policy responses. This option may be used ' | 1458 'policy responses. This option may be used ' |
| 1533 'multiple times to define a certificate chain. ' | 1459 'multiple times to define a certificate chain. ' |
| 1534 'The first element will be used for signing, ' | 1460 'The first element will be used for signing, ' |
| 1535 'the last element should be the root ' | 1461 'the last element should be the root ' |
| 1536 'certificate.') | 1462 'certificate.') |
| 1537 options, args = option_parser.parse_args() | 1463 options, args = option_parser.parse_args() |
| 1538 | 1464 |
| 1539 sys.exit(main(options, args)) | 1465 sys.exit(main(options, args)) |
| OLD | NEW |