167
167
# Some responses have bodies in which we have no interest
168
_body_ignored_responses = [301,302, 303, 307, 401, 403, 404]
168
_body_ignored_responses = [301,302, 303, 307, 400, 401, 403, 404, 501]
170
170
# in finish() below, we may have to discard several MB in the worst
171
171
# case. To avoid buffering that much, we read and discard by chunks
266
266
def cleanup_pipe(self):
267
267
"""Read the remaining bytes of the last response if any."""
268
268
if self._response is not None:
269
pending = self._response.finish()
270
# Warn the user (once)
271
if (self._ranges_received_whole_file is None
272
and self._response.status == 200
273
and pending and pending > self._range_warning_thresold
275
self._ranges_received_whole_file = True
277
'Got a 200 response when asking for multiple ranges,'
278
' does your server at %s:%s support range requests?',
279
self.host, self.port)
270
pending = self._response.finish()
271
# Warn the user (once)
272
if (self._ranges_received_whole_file is None
273
and self._response.status == 200
274
and pending and pending > self._range_warning_thresold
276
self._ranges_received_whole_file = True
278
'Got a 200 response when asking for multiple ranges,'
279
' does your server at %s:%s support range requests?',
280
self.host, self.port)
281
except socket.error, e:
282
# It's conceivable that the socket is in a bad state here
283
# (including some test cases) and in this case, it doesn't need
284
# cleaning anymore, so no need to fail, we just get rid of the
285
# socket and let callers reconnect
287
or e.args[0] not in (errno.ECONNRESET, errno.ECONNABORTED)):
280
290
self._response = None
281
291
# Preserve our preciousss
1202
1212
user = auth.get('user', None)
1203
1213
password = auth.get('password', None)
1204
1214
realm = auth['realm']
1215
port = auth.get('port', None)
1206
1217
if user is None:
1207
1218
user = auth_conf.get_user(auth['protocol'], auth['host'],
1208
port=auth['port'], path=auth['path'],
1219
port=port, path=auth['path'],
1209
1220
realm=realm, ask=True,
1210
1221
prompt=self.build_username_prompt(auth))
1211
1222
if user is not None and password is None:
1212
1223
password = auth_conf.get_password(
1213
auth['protocol'], auth['host'], user, port=auth['port'],
1224
auth['protocol'], auth['host'], user,
1214
1226
path=auth['path'], realm=realm,
1215
1227
prompt=self.build_password_prompt(auth))