~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_utils.py

Merge bzr.dev and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import urllib2
26
26
import urlparse
27
27
 
28
 
 
29
28
from bzrlib import (
 
29
    errors,
30
30
    tests,
31
31
    transport,
32
32
    )
33
 
from bzrlib.smart import protocol
 
33
from bzrlib.smart import medium, protocol
34
34
from bzrlib.tests import http_server
35
35
 
36
36
 
53
53
        self.send_response(200)
54
54
        self.send_header("Content-type", "application/octet-stream")
55
55
        t = transport.get_transport(self.server.test_case_server._home_dir)
 
56
        # if this fails, we should return 400 bad request, but failure is
 
57
        # failure for now - RBC 20060919
 
58
        data_length = int(self.headers['Content-Length'])
56
59
        # TODO: We might like to support streaming responses.  1.0 allows no
57
60
        # Content-length in this case, so for integrity we should perform our
58
61
        # own chunking within the stream.
60
63
        # the HTTP chunking as this will allow HTTP persistence safely, even if
61
64
        # we have to stop early due to error, but we would also have to use the
62
65
        # HTTP trailer facility which may not be widely available.
 
66
        request_bytes = self.rfile.read(data_length)
 
67
        protocol_factory, unused_bytes = medium._get_protocol_factory_for_bytes(
 
68
            request_bytes)
63
69
        out_buffer = StringIO()
64
 
        smart_protocol_request = protocol.SmartServerRequestProtocolOne(
65
 
                t, out_buffer.write)
66
 
        # if this fails, we should return 400 bad request, but failure is
67
 
        # failure for now - RBC 20060919
68
 
        data_length = int(self.headers['Content-Length'])
 
70
        smart_protocol_request = protocol_factory(t, out_buffer.write, '/')
69
71
        # Perhaps there should be a SmartServerHTTPMedium that takes care of
70
72
        # feeding the bytes in the http request to the smart_protocol_request,
71
73
        # but for now it's simpler to just feed the bytes directly.
72
 
        smart_protocol_request.accept_bytes(self.rfile.read(data_length))
73
 
        assert smart_protocol_request.next_read_size() == 0, (
74
 
            "not finished reading, but all data sent to protocol.")
 
74
        smart_protocol_request.accept_bytes(unused_bytes)
 
75
        if not (smart_protocol_request.next_read_size() == 0):
 
76
            raise errors.SmartProtocolError(
 
77
                "not finished reading, but all data sent to protocol.")
75
78
        self.send_header("Content-Length", str(len(out_buffer.getvalue())))
76
79
        self.end_headers()
77
80
        self.wfile.write(out_buffer.getvalue())