@@ -639,7 +639,7 @@ def _check_redirects(result: requests.Response) -> None:
639
639
)
640
640
)
641
641
642
- def http_request (
642
+ def backend_request (
643
643
self ,
644
644
verb : str ,
645
645
path : str ,
@@ -653,7 +653,7 @@ def http_request(
653
653
retry_transient_errors : Optional [bool ] = None ,
654
654
max_retries : int = 10 ,
655
655
** kwargs : Any ,
656
- ) -> requests . Response :
656
+ ) -> _backends . DefaultResponse :
657
657
"""Make an HTTP request to the Gitlab server.
658
658
659
659
Args:
@@ -722,7 +722,7 @@ def http_request(
722
722
cur_retries = 0
723
723
while True :
724
724
try :
725
- result = self ._backend .http_request (
725
+ backend_response = self ._backend .http_request (
726
726
method = verb ,
727
727
url = url ,
728
728
json = send_data .json ,
@@ -744,20 +744,26 @@ def http_request(
744
744
745
745
raise
746
746
747
- self ._check_redirects (result .response )
747
+ self ._check_redirects (backend_response .response )
748
748
749
- if 200 <= result .status_code < 300 :
750
- return result . response
749
+ if 200 <= backend_response .status_code < 300 :
750
+ return backend_response
751
751
752
752
def should_retry () -> bool :
753
- if result .status_code == 429 and obey_rate_limit :
753
+ if backend_response .status_code == 429 and obey_rate_limit :
754
754
return True
755
755
756
756
if not retry_transient_errors :
757
757
return False
758
- if result .status_code in gitlab .const .RETRYABLE_TRANSIENT_ERROR_CODES :
758
+ if (
759
+ backend_response .status_code
760
+ in gitlab .const .RETRYABLE_TRANSIENT_ERROR_CODES
761
+ ):
759
762
return True
760
- if result .status_code == 409 and "Resource lock" in result .reason :
763
+ if (
764
+ backend_response .status_code == 409
765
+ and "Resource lock" in backend_response .reason
766
+ ):
761
767
return True
762
768
763
769
return False
@@ -767,36 +773,74 @@ def should_retry() -> bool:
767
773
# https://docs.gitlab.com/ee/user/admin_area/settings/user_and_ip_rate_limits.html#response-headers
768
774
if max_retries == - 1 or cur_retries < max_retries :
769
775
wait_time = 2 ** cur_retries * 0.1
770
- if "Retry-After" in result .headers :
771
- wait_time = int (result .headers ["Retry-After" ])
772
- elif "RateLimit-Reset" in result .headers :
773
- wait_time = int (result .headers ["RateLimit-Reset" ]) - time .time ()
776
+ if "Retry-After" in backend_response .headers :
777
+ wait_time = int (backend_response .headers ["Retry-After" ])
778
+ elif "RateLimit-Reset" in backend_response .headers :
779
+ wait_time = (
780
+ int (backend_response .headers ["RateLimit-Reset" ])
781
+ - time .time ()
782
+ )
774
783
cur_retries += 1
775
784
time .sleep (wait_time )
776
785
continue
777
786
778
- error_message = result .content
787
+ error_message = backend_response .content
779
788
try :
780
- error_json = result .json ()
789
+ error_json = backend_response .json ()
781
790
for k in ("message" , "error" ):
782
791
if k in error_json :
783
792
error_message = error_json [k ]
784
793
except (KeyError , ValueError , TypeError ):
785
794
pass
786
795
787
- if result .status_code == 401 :
796
+ if backend_response .status_code == 401 :
788
797
raise gitlab .exceptions .GitlabAuthenticationError (
789
- response_code = result .status_code ,
798
+ response_code = backend_response .status_code ,
790
799
error_message = error_message ,
791
- response_body = result .content ,
800
+ response_body = backend_response .content ,
792
801
)
793
802
794
803
raise gitlab .exceptions .GitlabHttpError (
795
- response_code = result .status_code ,
804
+ response_code = backend_response .status_code ,
796
805
error_message = error_message ,
797
- response_body = result .content ,
806
+ response_body = backend_response .content ,
798
807
)
799
808
809
+ def http_request (
810
+ self ,
811
+ verb : str ,
812
+ path : str ,
813
+ query_data : Optional [Dict [str , Any ]] = None ,
814
+ post_data : Optional [Union [Dict [str , Any ], bytes ]] = None ,
815
+ raw : bool = False ,
816
+ streamed : bool = False ,
817
+ files : Optional [Dict [str , Any ]] = None ,
818
+ timeout : Optional [float ] = None ,
819
+ obey_rate_limit : bool = True ,
820
+ retry_transient_errors : Optional [bool ] = None ,
821
+ max_retries : int = 10 ,
822
+ ** kwargs : Any ,
823
+ ) -> requests .Response :
824
+ utils .warn (
825
+ "`http_request()` is deprecated and will be removed in a future version.\n "
826
+ "Please use `backend_request()` instead." ,
827
+ category = DeprecationWarning ,
828
+ )
829
+ return self .backend_request (
830
+ verb ,
831
+ path ,
832
+ query_data ,
833
+ post_data ,
834
+ raw ,
835
+ streamed ,
836
+ files ,
837
+ timeout ,
838
+ obey_rate_limit ,
839
+ retry_transient_errors ,
840
+ max_retries ,
841
+ ** kwargs ,
842
+ ).response
843
+
800
844
def http_get (
801
845
self ,
802
846
path : str ,
@@ -825,10 +869,11 @@ def http_get(
825
869
GitlabParsingError: If the json data could not be parsed
826
870
"""
827
871
query_data = query_data or {}
828
- result = self .http_request (
872
+ backend_response = self .backend_request (
829
873
"get" , path , query_data = query_data , streamed = streamed , ** kwargs
830
874
)
831
- content_type = utils .get_content_type (result .headers .get ("Content-Type" ))
875
+ content_type = utils .get_content_type (backend_response .headers .get ("Content-Type" ))
876
+ result = backend_response .response
832
877
833
878
if content_type == "application/json" and not streamed and not raw :
834
879
try :
@@ -861,8 +906,10 @@ def http_head(
861
906
"""
862
907
863
908
query_data = query_data or {}
864
- result = self .http_request ("head" , path , query_data = query_data , ** kwargs )
865
- return result .headers
909
+ backend_response = self .http_request (
910
+ "head" , path , query_data = query_data , ** kwargs
911
+ )
912
+ return backend_response .headers
866
913
867
914
def http_list (
868
915
self ,
@@ -1018,7 +1065,7 @@ def http_post(
1018
1065
query_data = query_data or {}
1019
1066
post_data = post_data or {}
1020
1067
1021
- result = self .http_request (
1068
+ backend_response = self .backend_request (
1022
1069
"post" ,
1023
1070
path ,
1024
1071
query_data = query_data ,
@@ -1027,7 +1074,8 @@ def http_post(
1027
1074
raw = raw ,
1028
1075
** kwargs ,
1029
1076
)
1030
- content_type = utils .get_content_type (result .headers .get ("Content-Type" ))
1077
+ content_type = utils .get_content_type (backend_response .headers .get ("Content-Type" ))
1078
+ result = backend_response .response
1031
1079
1032
1080
try :
1033
1081
if content_type == "application/json" :
@@ -1072,7 +1120,7 @@ def http_put(
1072
1120
query_data = query_data or {}
1073
1121
post_data = post_data or {}
1074
1122
1075
- result = self .http_request (
1123
+ backend_response = self .http_request (
1076
1124
"put" ,
1077
1125
path ,
1078
1126
query_data = query_data ,
@@ -1082,7 +1130,7 @@ def http_put(
1082
1130
** kwargs ,
1083
1131
)
1084
1132
try :
1085
- json_result = result .json ()
1133
+ json_result = backend_response .json ()
1086
1134
if TYPE_CHECKING :
1087
1135
assert isinstance (json_result , dict )
1088
1136
return json_result
@@ -1121,7 +1169,7 @@ def http_patch(
1121
1169
query_data = query_data or {}
1122
1170
post_data = post_data or {}
1123
1171
1124
- result = self .http_request (
1172
+ backend_response = self .http_request (
1125
1173
"patch" ,
1126
1174
path ,
1127
1175
query_data = query_data ,
@@ -1130,7 +1178,7 @@ def http_patch(
1130
1178
** kwargs ,
1131
1179
)
1132
1180
try :
1133
- json_result = result .json ()
1181
+ json_result = backend_response .json ()
1134
1182
if TYPE_CHECKING :
1135
1183
assert isinstance (json_result , dict )
1136
1184
return json_result
@@ -1153,7 +1201,8 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
1153
1201
Raises:
1154
1202
GitlabHttpError: When the return code is not 2xx
1155
1203
"""
1156
- return self .http_request ("delete" , path , ** kwargs )
1204
+ backend_response = self .backend_request ("delete" , path , ** kwargs )
1205
+ return backend_response .response
1157
1206
1158
1207
@gitlab .exceptions .on_http_error (gitlab .exceptions .GitlabSearchError )
1159
1208
def search (
@@ -1207,7 +1256,11 @@ def _query(
1207
1256
self , url : str , query_data : Optional [Dict [str , Any ]] = None , ** kwargs : Any
1208
1257
) -> None :
1209
1258
query_data = query_data or {}
1210
- result = self ._gl .http_request ("get" , url , query_data = query_data , ** kwargs )
1259
+ backend_response = self ._gl .backend_request (
1260
+ "get" , url , query_data = query_data , ** kwargs
1261
+ )
1262
+ result = backend_response .response
1263
+
1211
1264
try :
1212
1265
next_url = result .links ["next" ]["url" ]
1213
1266
except KeyError :
0 commit comments