@@ -531,19 +531,6 @@ ds3_error* net_process_request(const ds3_client* client,
531531
532532 ds3_log_message (client -> log , DS3_DEBUG , "Request completed with status code of: %d" , response_data .status_code );
533533
534- if (response_data .status_code == 307 ) {
535- ds3_log_message (client -> log , DS3_INFO , "Request encountered a 307 redirect" );
536- ds3_str_free (response_data .status_message );
537-
538- if (response_data .body != NULL ) {
539- g_byte_array_free (response_data .body , TRUE);
540- }
541- ds3_string_multimap_free (response_headers );
542- retry_count ++ ;
543- ds3_log_message (client -> log , DS3_DEBUG , "Retry Attempt: %d | Max Retries: %d" , retry_count , client -> num_redirects );
544- continue ;
545- }
546-
547534 if (response_data .status_code < 200 || response_data .status_code >= 300 ) {
548535 ds3_error * error = ds3_create_error (DS3_ERROR_BAD_STATUS_CODE , "Got an unexpected status code." );
549536 error -> error = g_new0 (ds3_error_response , 1 );
@@ -559,6 +546,21 @@ ds3_error* net_process_request(const ds3_client* client,
559546 ds3_string_multimap_free (response_headers );
560547 ds3_str_free (response_data .status_message );
561548 g_free (url );
549+
550+ if (response_data .status_code == 307 ) {
551+ ds3_log_message (client -> log , DS3_INFO , "Request encountered a 307 redirect" );
552+
553+ retry_count ++ ;
554+ ds3_log_message (client -> log , DS3_DEBUG , "Retry Attempt: %d | Max Retries: %d" , retry_count , client -> num_redirects );
555+
556+ if (retry_count == client -> num_redirects ) {
557+ ds3_str_free (error -> message );
558+ error -> message = ds3_str_init ("Encountered too many redirects while attempting to fulfill the request" );
559+ error -> code = DS3_ERROR_TOO_MANY_REDIRECTS ;
560+ } else {
561+ continue ;
562+ }
563+ }
562564 return error ;
563565 }
564566 g_byte_array_free (response_data .body , TRUE);
@@ -577,9 +579,6 @@ ds3_error* net_process_request(const ds3_client* client,
577579 }
578580 g_free (url );
579581
580- if (retry_count == client -> num_redirects ) {
581- return ds3_create_error (DS3_ERROR_TOO_MANY_REDIRECTS , "Encountered too many redirects while attempting to fulfill the request" );
582- }
583582 return NULL ;
584583}
585584
0 commit comments