1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
26
from bzrlib.transport import http
27
# TODO: handle_response should be integrated into the _urllib2_wrappers
27
# TODO: handle_response should be integrated into the http/__init__.py
28
28
from bzrlib.transport.http.response import handle_response
29
29
from bzrlib.transport.http._urllib2_wrappers import (
70
70
# Give back shared info
71
71
request.connection = connection
72
72
(auth, proxy_auth) = self._get_credentials()
73
# Clean the httplib.HTTPConnection pipeline in case the previous
74
# request couldn't do it
75
connection.cleanup_pipe()
74
77
# First request, intialize credentials.
75
78
# scheme and realm will be set by the _urllib2_wrappers.AuthHandler
123
126
if range_header is not None:
124
127
accepted_errors.append(206)
125
128
accepted_errors.append(400)
129
accepted_errors.append(416)
126
130
bytes = 'bytes=' + range_header
127
131
headers = {'Range': bytes}
133
137
code = response.code
134
138
if code == 404: # not found
135
self._get_connection().fake_close()
136
139
raise errors.NoSuchFile(abspath)
140
elif code in (400, 416):
141
# We don't know which, but one of the ranges we specified was
143
raise errors.InvalidHttpRange(abspath, range_header,
144
'Server return code %d' % code)
138
data = handle_response(abspath, code, response.headers, response)
139
# Close response to free the httplib.HTTPConnection pipeline
140
self._get_connection().fake_close()
146
data = handle_response(abspath, code, response.info(), response)
141
147
return code, data
143
149
def _post(self, body_bytes):
144
150
abspath = self._remote_path('.bzr/smart')
145
151
response = self._perform(Request('POST', abspath, body_bytes))
146
152
code = response.code
147
data = handle_response(abspath, code, response.headers, response)
148
# Close response to free the httplib.HTTPConnection pipeline
149
self._get_connection().fake_close()
153
data = handle_response(abspath, code, response.info(), response)
150
154
return code, data
152
156
def _head(self, relpath):