~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: paulbrianstewart at gmail
  • Date: 2011-08-13 23:07:36 UTC
  • mto: This revision was merged to the branch mainline in revision 6069.
  • Revision ID: paulbrianstewart@gmail.com-20110813230736-lqi6eek015wh23yv
Added punctuation to the commit message

Show diffs side-by-side

added added

removed removed

Lines of Context:
1048
1048
        self.assertEqual('single', t._range_hint)
1049
1049
 
1050
1050
 
1051
 
class TruncatedBeforeBoundaryRequestHandler(
1052
 
    http_server.TestingHTTPRequestHandler):
1053
 
    """Truncation before a boundary, like in bug 198646"""
1054
 
 
1055
 
    _truncated_ranges = 1
1056
 
 
1057
 
    def get_multiple_ranges(self, file, file_size, ranges):
1058
 
        self.send_response(206)
1059
 
        self.send_header('Accept-Ranges', 'bytes')
1060
 
        boundary = 'tagada'
1061
 
        self.send_header('Content-Type',
1062
 
                         'multipart/byteranges; boundary=%s' % boundary)
1063
 
        boundary_line = '--%s\r\n' % boundary
1064
 
        # Calculate the Content-Length
1065
 
        content_length = 0
1066
 
        for (start, end) in ranges:
1067
 
            content_length += len(boundary_line)
1068
 
            content_length += self._header_line_length(
1069
 
                'Content-type', 'application/octet-stream')
1070
 
            content_length += self._header_line_length(
1071
 
                'Content-Range', 'bytes %d-%d/%d' % (start, end, file_size))
1072
 
            content_length += len('\r\n') # end headers
1073
 
            content_length += end - start # + 1
1074
 
        content_length += len(boundary_line)
1075
 
        self.send_header('Content-length', content_length)
1076
 
        self.end_headers()
1077
 
 
1078
 
        # Send the multipart body
1079
 
        cur = 0
1080
 
        for (start, end) in ranges:
1081
 
            if cur + self._truncated_ranges >= len(ranges):
1082
 
                # Abruptly ends the response and close the connection
1083
 
                self.close_connection = 1
1084
 
                return
1085
 
            self.wfile.write(boundary_line)
1086
 
            self.send_header('Content-type', 'application/octet-stream')
1087
 
            self.send_header('Content-Range', 'bytes %d-%d/%d'
1088
 
                             % (start, end, file_size))
1089
 
            self.end_headers()
1090
 
            self.send_range_content(file, start, end - start + 1)
1091
 
            cur += 1
1092
 
        # Final boundary
1093
 
        self.wfile.write(boundary_line)
1094
 
 
1095
 
 
1096
 
class TestTruncatedBeforeBoundary(TestSpecificRequestHandler):
1097
 
    """Tests the case of bug 198646, disconnecting before a boundary."""
1098
 
 
1099
 
    _req_handler_class = TruncatedBeforeBoundaryRequestHandler
1100
 
 
1101
 
    def setUp(self):
1102
 
        super(TestTruncatedBeforeBoundary, self).setUp()
1103
 
        self.build_tree_contents([('a', '0123456789')],)
1104
 
 
1105
 
    def test_readv_with_short_reads(self):
1106
 
        server = self.get_readonly_server()
1107
 
        t = self.get_readonly_transport()
1108
 
        # Force separate ranges for each offset
1109
 
        t._bytes_to_read_before_seek = 0
1110
 
        ireadv = iter(t.readv('a', ((0, 1), (2, 1), (4, 2), (9, 1))))
1111
 
        self.assertEqual((0, '0'), ireadv.next())
1112
 
        self.assertEqual((2, '2'), ireadv.next())
1113
 
        self.assertEqual((4, '45'), ireadv.next())
1114
 
        self.assertEqual((9, '9'), ireadv.next())
1115
 
 
1116
 
 
1117
1051
class LimitedRangeRequestHandler(http_server.TestingHTTPRequestHandler):
1118
1052
    """Errors out when range specifiers exceed the limit"""
1119
1053
 
1767
1701
                                     http_utils.ProxyDigestAuthServer):
1768
1702
            raise tests.TestNotApplicable('HTTP/proxy auth digest only test')
1769
1703
        if self._testing_pycurl():
1770
 
            self.knownFailure(
 
1704
            raise tests.KnownFailure(
1771
1705
                'pycurl does not handle a nonce change')
1772
1706
        self.server.add_user('joe', 'foo')
1773
1707
        t = self.get_user_transport('joe', 'foo')
1855
1789
        if self._testing_pycurl():
1856
1790
            import pycurl
1857
1791
            if pycurl.version_info()[1] < '7.16.0':
1858
 
                self.knownFailure(
 
1792
                raise tests.KnownFailure(
1859
1793
                    'pycurl < 7.16.0 does not handle empty proxy passwords')
1860
1794
        super(TestProxyAuth, self).test_empty_pass()
1861
1795
 
2027
1961
        r = t._redirected_to('http://www.example.com/foo',
2028
1962
                             'https://foo.example.com/foo')
2029
1963
        self.assertIsInstance(r, type(t))
2030
 
        self.assertEqual(t._parsed_url.user, r._parsed_url.user)
 
1964
        self.assertEqual(t._user, r._user)
2031
1965
 
2032
1966
 
2033
1967
class PredefinedRequestHandler(http_server.TestingHTTPRequestHandler):