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 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
931 else: | 931 else: |
932 # Could be more generic once we support mime-type sniffing, but for | 932 # Could be more generic once we support mime-type sniffing, but for |
933 # now we need to set it explicitly. | 933 # now we need to set it explicitly. |
934 | 934 |
935 range = self.headers.get('Range') | 935 range = self.headers.get('Range') |
936 if range and range.startswith('bytes='): | 936 if range and range.startswith('bytes='): |
937 # Note this doesn't handle all valid byte range values (i.e. open ended | 937 # Note this doesn't handle all valid byte range values (i.e. open ended |
938 # ones), just enough for what we needed so far. | 938 # ones), just enough for what we needed so far. |
939 range = range[6:].split('-') | 939 range = range[6:].split('-') |
940 start = int(range[0]) | 940 start = int(range[0]) |
941 end = int(range[1]) | 941 if range[1]: |
942 end = int(range[1]) | |
943 else: | |
944 end = len(data) | |
scherkus (not reviewing)
2011/11/10 07:47:58
if this implements open ended ranges then it looks
Shishir
2011/11/14 19:27:23
Done.
| |
942 | 945 |
943 self.send_response(206) | 946 self.send_response(206) |
944 content_range = 'bytes ' + str(start) + '-' + str(end) + '/' + \ | 947 content_range = 'bytes ' + str(start) + '-' + str(end) + '/' + \ |
945 str(len(data)) | 948 str(len(data)) |
946 self.send_header('Content-Range', content_range) | 949 self.send_header('Content-Range', content_range) |
947 data = data[start: end + 1] | 950 data = data[start: end + 1] |
948 else: | 951 else: |
949 self.send_response(200) | 952 self.send_response(200) |
950 | 953 |
951 self.send_header('Content-Type', self.GetMIMETypeFromName(file_path)) | 954 self.send_header('Content-Type', self.GetMIMETypeFromName(file_path)) |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1950 'random key if none is specified on the command ' | 1953 'random key if none is specified on the command ' |
1951 'line.') | 1954 'line.') |
1952 option_parser.add_option('', '--policy-user', default='user@example.com', | 1955 option_parser.add_option('', '--policy-user', default='user@example.com', |
1953 dest='policy_user', | 1956 dest='policy_user', |
1954 help='Specify the user name the server should ' | 1957 help='Specify the user name the server should ' |
1955 'report back to the client as the user owning the ' | 1958 'report back to the client as the user owning the ' |
1956 'token used for making the policy request.') | 1959 'token used for making the policy request.') |
1957 options, args = option_parser.parse_args() | 1960 options, args = option_parser.parse_args() |
1958 | 1961 |
1959 sys.exit(main(options, args)) | 1962 sys.exit(main(options, args)) |
OLD | NEW |