Skip to content

Commit

Permalink
Merge pull request #261 from l-iberty/master
Browse files Browse the repository at this point in the history
重试逻辑优化
  • Loading branch information
l-iberty committed Jan 3, 2024
2 parents 4ea447d + 07e1fd3 commit 0e2fd8f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion qcloud_cos/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,23 @@ def send_request(self, method, url, bucket, timeout=30, cos_request=True, ci_req
elif method == 'HEAD':
res = self._session.head(url, timeout=timeout, proxies=self._conf._proxies, **kwargs)
if res.status_code < 400: # 2xx和3xx都认为是成功的
if res.status_code == 301 or res.status_code == 302 or res.status_code == 307:
if j < self._retry and 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:
url = switch_hostname_for_url(url)
domain_switched = True
continue
return res
elif res.status_code < 500: # 4xx 不重试
if j < self._retry and 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:
url = switch_hostname_for_url(url)
domain_switched = True
continue
break
else:
if j < self._retry and client_can_retry(file_position, **kwargs):
if not domain_switched and self._conf._auto_switch_domain_on_retry and self._conf._ip is None:
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:
url = switch_hostname_for_url(url)
domain_switched = True
continue
Expand Down

0 comments on commit 0e2fd8f

Please sign in to comment.