| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for | 6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for |
| 7 testing Chrome. | 7 testing Chrome. |
| 8 | 8 |
| 9 It supports several test URLs, as specified by the handlers in TestPageHandler. | 9 It supports several test URLs, as specified by the handlers in TestPageHandler. |
| 10 By default, it listens on an ephemeral port and sends the port number back to | 10 By default, it listens on an ephemeral port and sends the port number back to |
| (...skipping 1611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1622 if fail_precondition != 0: | 1622 if fail_precondition != 0: |
| 1623 TestPageHandler.fail_precondition[token] -= 1 | 1623 TestPageHandler.fail_precondition[token] -= 1 |
| 1624 | 1624 |
| 1625 first_byte = 0 | 1625 first_byte = 0 |
| 1626 last_byte = size - 1 | 1626 last_byte = size - 1 |
| 1627 | 1627 |
| 1628 # Does that define what we want to return, or do we need to apply | 1628 # Does that define what we want to return, or do we need to apply |
| 1629 # a range? | 1629 # a range? |
| 1630 range_response = False | 1630 range_response = False |
| 1631 range_header = self.headers.getheader('range') | 1631 range_header = self.headers.getheader('range') |
| 1632 |
| 1633 if fail_precondition and self.headers.getheader('If-Range'): |
| 1634 # Failing a precondition for an If-Range just means that we are going to |
| 1635 # return the entire entity ignoring the Range header. |
| 1636 respond_to_range = False |
| 1637 |
| 1632 if range_header and respond_to_range: | 1638 if range_header and respond_to_range: |
| 1633 mo = re.match("bytes=(\d*)-(\d*)", range_header) | 1639 mo = re.match("bytes=(\d*)-(\d*)", range_header) |
| 1634 if mo.group(1): | 1640 if mo.group(1): |
| 1635 first_byte = int(mo.group(1)) | 1641 first_byte = int(mo.group(1)) |
| 1636 if mo.group(2): | 1642 if mo.group(2): |
| 1637 last_byte = int(mo.group(2)) | 1643 last_byte = int(mo.group(2)) |
| 1638 if last_byte > size - 1: | 1644 if last_byte > size - 1: |
| 1639 last_byte = size - 1 | 1645 last_byte = size - 1 |
| 1640 range_response = True | 1646 range_response = True |
| 1641 if last_byte < first_byte: | 1647 if last_byte < first_byte: |
| 1642 return False | 1648 return False |
| 1643 | 1649 |
| 1644 if (fail_precondition and | |
| 1645 (self.headers.getheader('If-Modified-Since') or | |
| 1646 self.headers.getheader('If-Match'))): | |
| 1647 self.send_response(412) | |
| 1648 self.end_headers() | |
| 1649 return True | |
| 1650 | |
| 1651 if range_response: | 1650 if range_response: |
| 1652 self.send_response(206) | 1651 self.send_response(206) |
| 1653 self.send_header('Content-Range', | 1652 self.send_header('Content-Range', |
| 1654 'bytes %d-%d/%d' % (first_byte, last_byte, size)) | 1653 'bytes %d-%d/%d' % (first_byte, last_byte, size)) |
| 1655 else: | 1654 else: |
| 1656 self.send_response(200) | 1655 self.send_response(200) |
| 1657 self.send_header('Content-Type', 'application/octet-stream') | 1656 self.send_header('Content-Type', 'application/octet-stream') |
| 1658 self.send_header('Content-Length', last_byte - first_byte + 1) | 1657 self.send_header('Content-Length', last_byte - first_byte + 1) |
| 1659 if send_verifiers: | 1658 if send_verifiers: |
| 1660 # If fail_precondition is non-zero, then the ETag for each request will be | 1659 # If fail_precondition is non-zero, then the ETag for each request will be |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2310 'an anonymous user.') | 2309 'an anonymous user.') |
| 2311 self.option_parser.add_option('--disable-channel-id', action='store_true') | 2310 self.option_parser.add_option('--disable-channel-id', action='store_true') |
| 2312 self.option_parser.add_option('--disable-extended-master-secret', | 2311 self.option_parser.add_option('--disable-extended-master-secret', |
| 2313 action='store_true') | 2312 action='store_true') |
| 2314 self.option_parser.add_option('--token-binding-params', action='append', | 2313 self.option_parser.add_option('--token-binding-params', action='append', |
| 2315 default=[], type='int') | 2314 default=[], type='int') |
| 2316 | 2315 |
| 2317 | 2316 |
| 2318 if __name__ == '__main__': | 2317 if __name__ == '__main__': |
| 2319 sys.exit(ServerRunner().main()) | 2318 sys.exit(ServerRunner().main()) |
| OLD | NEW |