/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/wsgi.py

  • Committer: Andrew Bennetts
  • Date: 2007-12-13 22:22:58 UTC
  • mto: This revision was merged to the branch mainline in revision 3320.
  • Revision ID: andrew.bennetts@canonical.com-20071213222258-mh7mq5gtxqn4yceb
All WSGI tests passing, and manual testing works too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        base_transport = get_transport('readonly+' + local_url)
40
40
    else:
41
41
        base_transport = get_transport(local_url)
42
 
    app = SmartWSGIApp(base_transport)
43
 
    app = RelpathSetter(app, prefix, path_var)
 
42
    app = SmartWSGIApp(base_transport, prefix)
 
43
    app = RelpathSetter(app, '', path_var)
44
44
    return app
45
45
 
46
46
 
116
116
            return []
117
117
 
118
118
        relpath = environ['bzrlib.relpath']
119
 
        transport = self.backing_transport.clone(relpath)
 
119
        # 1. subtract HTTP path from rcp ("adjusted rcp")
 
120
        #    1a.  If HTTP path unconsumed, clone backing transport with
 
121
        #         remainder ("adjusted transport")
 
122
        # 2. feed HPSS request path + adjusted/backing transport + adjusted
 
123
        #    rcp?
 
124
 
 
125
        if not relpath.startswith('/'):
 
126
            relpath = '/' + relpath
 
127
        if not relpath.endswith('/'):
 
128
            relpath += '/'
 
129
 
 
130
        # (relpath='/foo/bar/', rcp='/foo/' -> (rp 'bar', arcp '/')
 
131
        #  relpath='/foo/', rcp='/foo/bar/' -> (rp '/', arcp '/bar')
 
132
        if relpath.startswith(self.root_client_path):
 
133
            # The entire root client path is part of the relpath.
 
134
            adjusted_rcp = None
 
135
            # Consume the relpath part we just subtracted
 
136
            adjusted_relpath = relpath[len(self.root_client_path):]
 
137
        elif self.root_client_path.startswith(relpath):
 
138
            # The relpath traverses some of the mandatory root client path.
 
139
            # Subtract relpath from HTTP request
 
140
            adjusted_rcp = '/' + self.root_client_path[len(relpath):]
 
141
            # The entire relpath was consumed.
 
142
            adjusted_relpath = '.'
 
143
        else:
 
144
            adjusted_rcp = self.root_client_path
 
145
            adjusted_relpath = relpath
 
146
 
 
147
        if adjusted_relpath.startswith('/'):
 
148
            adjusted_relpath = adjusted_relpath[1:]
 
149
        assert not adjusted_relpath.startswith('/')
 
150
 
 
151
        transport = self.backing_transport.clone(adjusted_relpath)
 
152
 
 
153
 
 
154
        # Random Notes:
 
155
 
 
156
        #transport = self.backing_transport.clone(relpath)
120
157
        out_buffer = StringIO()
121
158
        request_data_length = int(environ['CONTENT_LENGTH'])
122
159
        request_data_bytes = environ['wsgi.input'].read(request_data_length)
123
160
        smart_protocol_request = self.make_request(
124
 
            transport, out_buffer.write, request_data_bytes)
 
161
            transport, out_buffer.write, request_data_bytes, adjusted_rcp)
125
162
        if smart_protocol_request.next_read_size() != 0:
126
163
            # The request appears to be incomplete, or perhaps it's just a
127
164
            # newer version we don't understand.  Regardless, all we can do
135
172
        start_response('200 OK', headers)
136
173
        return [response_data]
137
174
 
138
 
    def make_request(self, transport, write_func, request_bytes):
 
175
    def make_request(self, transport, write_func, request_bytes, rcp):
139
176
        # XXX: This duplicates the logic in
140
177
        # SmartServerStreamMedium._build_protocol.
141
178
        if request_bytes.startswith(protocol.REQUEST_VERSION_TWO):
144
181
        else:
145
182
            protocol_class = protocol.SmartServerRequestProtocolOne
146
183
        server_protocol = protocol_class(
147
 
            transport, write_func, self.root_client_path)
 
184
            transport, write_func, rcp)
148
185
        server_protocol.accept_bytes(request_bytes)
149
186
        return server_protocol