47
from bzrlib.transport.http import response
47
from bzrlib.transport.http import (
53
class ReadSocket(object):
54
"""A socket-like object that can be given a predefined content."""
56
def __init__(self, data):
57
self.readfile = StringIO(data)
59
def makefile(self, mode='r', bufsize=None):
62
class FakeHTTPConnection(_urllib2_wrappers.HTTPConnection):
64
def __init__(self, sock):
65
_urllib2_wrappers.HTTPConnection.__init__(self, 'localhost')
66
# Set the socket to bypass the connection
70
"""Ignores the writes on the socket."""
74
class TestHTTPConnection(tests.TestCase):
76
def test_cleanup_pipe(self):
77
sock = ReadSocket("""HTTP/1.1 200 OK\r
78
Content-Type: text/plain; charset=UTF-8\r
83
conn = FakeHTTPConnection(sock)
84
# Simulate the request sending so that the connection will be able to
86
conn.putrequest('GET', 'http://localhost/fictious')
88
# Now, get the response
89
resp = conn.getresponse()
90
# Read part of the response
91
self.assertEquals('0123456789\n', resp.read(11))
92
# Override the thresold to force the warning emission
93
conn._range_warning_thresold = 6 # There are 7 bytes pending
95
self.assertContainsRe(self._get_log(keep_log_file=True),
96
'Got a 200 response when asking')
50
99
class TestRangeFileMixin(object):