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/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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 else: | 921 else: |
922 # Could be more generic once we support mime-type sniffing, but for | 922 # Could be more generic once we support mime-type sniffing, but for |
923 # now we need to set it explicitly. | 923 # now we need to set it explicitly. |
924 | 924 |
925 range = self.headers.get('Range') | 925 range = self.headers.get('Range') |
926 if range and range.startswith('bytes='): | 926 if range and range.startswith('bytes='): |
927 # Note this doesn't handle all valid byte range values (i.e. open ended | 927 # Note this doesn't handle all valid byte range values (i.e. open ended |
928 # ones), just enough for what we needed so far. | 928 # ones), just enough for what we needed so far. |
929 range = range[6:].split('-') | 929 range = range[6:].split('-') |
930 start = int(range[0]) | 930 start = int(range[0]) |
931 end = int(range[1]) | 931 if range[1]: |
| 932 end = int(range[1]) |
| 933 else: |
| 934 end = len(data) |
932 | 935 |
933 self.send_response(206) | 936 self.send_response(206) |
934 content_range = 'bytes ' + str(start) + '-' + str(end) + '/' + \ | 937 content_range = 'bytes ' + str(start) + '-' + str(end) + '/' + \ |
935 str(len(data)) | 938 str(len(data)) |
936 self.send_header('Content-Range', content_range) | 939 self.send_header('Content-Range', content_range) |
937 data = data[start: end + 1] | 940 data = data[start: end + 1] |
938 else: | 941 else: |
939 self.send_response(200) | 942 self.send_response(200) |
940 | 943 |
941 self.send_header('Content-type', self.GetMIMETypeFromName(file_path)) | 944 self.send_header('Content-type', self.GetMIMETypeFromName(file_path)) |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 'random key if none is specified on the command ' | 1918 'random key if none is specified on the command ' |
1916 'line.') | 1919 'line.') |
1917 option_parser.add_option('', '--policy-user', default='user@example.com', | 1920 option_parser.add_option('', '--policy-user', default='user@example.com', |
1918 dest='policy_user', | 1921 dest='policy_user', |
1919 help='Specify the user name the server should ' | 1922 help='Specify the user name the server should ' |
1920 'report back to the client as the user owning the ' | 1923 'report back to the client as the user owning the ' |
1921 'token used for making the policy request.') | 1924 'token used for making the policy request.') |
1922 options, args = option_parser.parse_args() | 1925 options, args = option_parser.parse_args() |
1923 | 1926 |
1924 sys.exit(main(options, args)) | 1927 sys.exit(main(options, args)) |
OLD | NEW |