39
39
base_transport = get_transport('readonly+' + local_url)
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)
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
125
if not relpath.startswith('/'):
126
relpath = '/' + relpath
127
if not relpath.endswith('/'):
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.
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 = '.'
144
adjusted_rcp = self.root_client_path
145
adjusted_relpath = relpath
147
if adjusted_relpath.startswith('/'):
148
adjusted_relpath = adjusted_relpath[1:]
149
assert not adjusted_relpath.startswith('/')
151
transport = self.backing_transport.clone(adjusted_relpath)
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]
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):
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