@@ -171,7 +171,8 @@ def __init__(self, access_key_id, secret_access_key, is_secure=True, server=None
171
171
port = None , max_retry_count = 3 , timeout = 60 , chunk_size = 65536 ,
172
172
long_conn_mode = False , proxy_host = None , proxy_port = None ,
173
173
proxy_username = None , proxy_password = None , security_token = None ,
174
- custom_ciphers = None , use_http2 = False , is_signature_negotiation = True , is_cname = False ):
174
+ custom_ciphers = None , use_http2 = False , is_signature_negotiation = True , is_cname = False ,
175
+ max_redirect_count = 10 ):
175
176
self .securityProvider = _SecurityProvider (access_key_id , secret_access_key , security_token )
176
177
server = server if server is not None else ''
177
178
server = util .to_string (util .safe_encode (server ))
@@ -212,6 +213,7 @@ def __init__(self, access_key_id, secret_access_key, is_secure=True, server=None
212
213
self .use_http2 = use_http2
213
214
self .is_signature_negotiation = is_signature_negotiation
214
215
self .is_cname = is_cname
216
+ self .max_redirect_count = max_redirect_count
215
217
216
218
if self .path_style or self .is_cname :
217
219
self .is_signature_negotiation = False
@@ -332,9 +334,17 @@ def _make_post_request(self, bucketName, objectKey=None, pathArgs=None, headers=
332
334
def _make_put_request (self , bucketName , objectKey = None , pathArgs = None , headers = None , entity = None , chunkedMode = False , methodName = None , readable = False ):
333
335
return self ._make_request_with_retry (const .HTTP_METHOD_PUT , bucketName , objectKey , pathArgs , headers , entity , chunkedMode , methodName = methodName , readable = readable )
334
336
337
+ def _make_error_result (self , e , ret ):
338
+ self .log_client .log (ERROR , 'request error, %s' % e )
339
+ self .log_client .log (ERROR , traceback .format_exc ())
340
+ if ret is not None :
341
+ return ret
342
+ raise e
343
+
335
344
def _make_request_with_retry (self , methodType , bucketName , objectKey = None , pathArgs = None , headers = None ,
336
345
entity = None , chunkedMode = False , methodName = None , readable = False , parseMethod = None , redirectLocation = None , skipAuthentication = False ):
337
346
flag = 0
347
+ redirect_count = 0
338
348
conn = None
339
349
_redirectLocation = redirectLocation
340
350
while True :
@@ -349,16 +359,16 @@ def _make_request_with_retry(self, methodType, bucketName, objectKey=None, pathA
349
359
else :
350
360
util .close_conn (conn , self .log_client )
351
361
if isinstance (e , _RedirectException ):
362
+ redirect_count += 1
352
363
_redirectLocation = e .location
353
364
flag -= 1
354
365
ret = e .result
355
-
366
+ if redirect_count >= self .max_redirect_count :
367
+ self .log_client .log (ERROR , 'request redirect count [%d] greater than max redirect count [%d]' % (
368
+ redirect_count , self .max_redirect_count ))
369
+ return self ._make_error_result (e , ret )
356
370
if flag >= self .max_retry_count or readable :
357
- self .log_client .log (ERROR , 'request error, %s' % e )
358
- self .log_client .log (ERROR , traceback .format_exc ())
359
- if ret is not None :
360
- return ret
361
- raise e
371
+ return self ._make_error_result (e , ret )
362
372
flag += 1
363
373
time .sleep (math .pow (2 , flag ) * 0.05 )
364
374
self .log_client .log (WARNING , 'request again, time:%d' % int (flag ))
@@ -769,6 +779,7 @@ def _parse_xml_internal(self, result, methodName=None, chuckSize=65536, readable
769
779
break
770
780
xml = chunk if xml is None else xml + chunk
771
781
header = self ._rename_response_headers (headers )
782
+ indicator = headers .get (self .ha .indicator_header ())
772
783
if status < 300 :
773
784
if methodName is not None :
774
785
parseMethod = getattr (self .convertor , 'parse' + methodName [:1 ].upper () + methodName [1 :])
@@ -799,7 +810,7 @@ def _parse_xml_internal(self, result, methodName=None, chuckSize=65536, readable
799
810
800
811
if not requestId :
801
812
requestId = headers .get (self .ha .request_id_header ())
802
-
813
+
803
814
self .log_client .log (DEBUG , 'http response result:status:%d,reason:%s,code:%s,message:%s,headers:%s' ,
804
815
status , reason , code , message , header )
805
816
@@ -808,7 +819,7 @@ def _parse_xml_internal(self, result, methodName=None, chuckSize=65536, readable
808
819
status , reason , code , message , requestId )
809
820
810
821
ret = GetResult (code = code , message = message , status = status , reason = reason , body = body ,
811
- requestId = requestId , hostId = hostId , resource = resource , header = header )
822
+ requestId = requestId , hostId = hostId , resource = resource , header = header , indicator = indicator )
812
823
813
824
if not readable :
814
825
if status >= 300 and status < 400 and status != 304 and const .LOCATION_HEADER .lower () in headers :
0 commit comments