Skip to content

Commit 0e2fd8f

Browse files
authored
Merge pull request #261 from l-iberty/master
重试逻辑优化
2 parents 4ea447d + 07e1fd3 commit 0e2fd8f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

qcloud_cos/cos_client.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,23 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, ci_req
374374
elif method == 'HEAD':
375375
res = self._session.head(url, timeout=timeout, proxies=self._conf._proxies, **kwargs)
376376
if res.status_code < 400: # 2xx和3xx都认为是成功的
377+
if res.status_code == 301 or res.status_code == 302 or res.status_code == 307:
378+
if j < self._retry and not 'x-cos-request-id' in res.headers \
379+
and not domain_switched and self._conf._auto_switch_domain_on_retry and self._conf._ip is None:
380+
url = switch_hostname_for_url(url)
381+
domain_switched = True
382+
continue
377383
return res
378384
elif res.status_code < 500: # 4xx 不重试
385+
if j < self._retry and not 'x-cos-request-id' in res.headers \
386+
and not domain_switched and self._conf._auto_switch_domain_on_retry and self._conf._ip is None:
387+
url = switch_hostname_for_url(url)
388+
domain_switched = True
389+
continue
379390
break
380391
else:
381392
if j < self._retry and client_can_retry(file_position, **kwargs):
382-
if not domain_switched and self._conf._auto_switch_domain_on_retry and self._conf._ip is None:
393+
if not 'x-cos-request-id' in res.headers and not domain_switched and self._conf._auto_switch_domain_on_retry and self._conf._ip is None:
383394
url = switch_hostname_for_url(url)
384395
domain_switched = True
385396
continue

0 commit comments

Comments
 (0)