@@ -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:
@@ -724,7 +724,7 @@ def http_request(
724
724
cur_retries = 0
725
725
while True :
726
726
try :
727
- result = self ._backend .http_request (
727
+ backend_response = self ._backend .http_request (
728
728
method = verb ,
729
729
url = url ,
730
730
json = json ,
@@ -746,20 +746,26 @@ def http_request(
746
746
747
747
raise
748
748
749
- self ._check_redirects (result .response )
749
+ self ._check_redirects (backend_response .response )
750
750
751
- if 200 <= result .status_code < 300 :
752
- return result . response
751
+ if 200 <= backend_response .status_code < 300 :
752
+ return backend_response
753
753
754
754
def should_retry () -> bool :
755
- if result .status_code == 429 and obey_rate_limit :
755
+ if backend_response .status_code == 429 and obey_rate_limit :
756
756
return True
757
757
758
758
if not retry_transient_errors :
759
759
return False
760
- if result .status_code in gitlab .const .RETRYABLE_TRANSIENT_ERROR_CODES :
760
+ if (
761
+ backend_response .status_code
762
+ in gitlab .const .RETRYABLE_TRANSIENT_ERROR_CODES
763
+ ):
761
764
return True
762
- if result .status_code == 409 and "Resource lock" in result .reason :
765
+ if (
766
+ backend_response .status_code == 409
767
+ and "Resource lock" in backend_response .reason
768
+ ):
763
769
return True
764
770
765
771
return False
@@ -769,36 +775,74 @@ def should_retry() -> bool:
769
775
# https://docs.gitlab.com/ee/user/admin_area/settings/user_and_ip_rate_limits.html#response-headers
770
776
if max_retries == - 1 or cur_retries < max_retries :
771
777
wait_time = 2 ** cur_retries * 0.1
772
- if "Retry-After" in result .headers :
773
- wait_time = int (result .headers ["Retry-After" ])
774
- elif "RateLimit-Reset" in result .headers :
775
- wait_time = int (result .headers ["RateLimit-Reset" ]) - time .time ()
778
+ if "Retry-After" in backend_response .headers :
779
+ wait_time = int (backend_response .headers ["Retry-After" ])
780
+ elif "RateLimit-Reset" in backend_response .headers :
781
+ wait_time = (
782
+ int (backend_response .headers ["RateLimit-Reset" ])
783
+ - time .time ()
784
+ )
776
785
cur_retries += 1
777
786
time .sleep (wait_time )
778
787
continue
779
788
780
- error_message = result .content
789
+ error_message = backend_response .content
781
790
try :
782
- error_json = result .json ()
791
+ error_json = backend_response .json ()
783
792
for k in ("message" , "error" ):
784
793
if k in error_json :
785
794
error_message = error_json [k ]
786
795
except (KeyError , ValueError , TypeError ):
787
796
pass
788
797
789
- if result .status_code == 401 :
798
+ if backend_response .status_code == 401 :
790
799
raise gitlab .exceptions .GitlabAuthenticationError (
791
- response_code = result .status_code ,
800
+ response_code = backend_response .status_code ,
792
801
error_message = error_message ,
793
- response_body = result .content ,
802
+ response_body = backend_response .content ,
794
803
)
795
804
796
805
raise gitlab .exceptions .GitlabHttpError (
797
- response_code = result .status_code ,
806
+ response_code = backend_response .status_code ,
798
807
error_message = error_message ,
799
- response_body = result .content ,
808
+ response_body = backend_response .content ,
800
809
)
801
810
811
+ def http_request (
812
+ self ,
813
+ verb : str ,
814
+ path : str ,
815
+ query_data : Optional [Dict [str , Any ]] = None ,
816
+ post_data : Optional [Union [Dict [str , Any ], bytes ]] = None ,
817
+ raw : bool = False ,
818
+ streamed : bool = False ,
819
+ files : Optional [Dict [str , Any ]] = None ,
820
+ timeout : Optional [float ] = None ,
821
+ obey_rate_limit : bool = True ,
822
+ retry_transient_errors : Optional [bool ] = None ,
823
+ max_retries : int = 10 ,
824
+ ** kwargs : Any ,
825
+ ) -> requests .Response :
826
+ utils .warn (
827
+ "`http_request()` is deprecated and will be removed in a future version.\n "
828
+ "Please use `backend_request()` instead." ,
829
+ category = DeprecationWarning ,
830
+ )
831
+ return self .backend_request (
832
+ verb ,
833
+ path ,
834
+ query_data ,
835
+ post_data ,
836
+ raw ,
837
+ streamed ,
838
+ files ,
839
+ timeout ,
840
+ obey_rate_limit ,
841
+ retry_transient_errors ,
842
+ max_retries ,
843
+ ** kwargs ,
844
+ ).response
845
+
802
846
def http_get (
803
847
self ,
804
848
path : str ,
@@ -827,9 +871,10 @@ def http_get(
827
871
GitlabParsingError: If the json data could not be parsed
828
872
"""
829
873
query_data = query_data or {}
830
- result = self .http_request (
874
+ backend_response = self .backend_request (
831
875
"get" , path , query_data = query_data , streamed = streamed , ** kwargs
832
876
)
877
+ result = backend_response .response
833
878
834
879
if (
835
880
result .headers ["Content-Type" ] == "application/json"
@@ -866,8 +911,10 @@ def http_head(
866
911
"""
867
912
868
913
query_data = query_data or {}
869
- result = self .http_request ("head" , path , query_data = query_data , ** kwargs )
870
- return result .headers
914
+ backend_response = self .http_request (
915
+ "head" , path , query_data = query_data , ** kwargs
916
+ )
917
+ return backend_response .headers
871
918
872
919
def http_list (
873
920
self ,
@@ -1023,7 +1070,7 @@ def http_post(
1023
1070
query_data = query_data or {}
1024
1071
post_data = post_data or {}
1025
1072
1026
- result = self .http_request (
1073
+ backend_response = self .backend_request (
1027
1074
"post" ,
1028
1075
path ,
1029
1076
query_data = query_data ,
@@ -1032,6 +1079,8 @@ def http_post(
1032
1079
raw = raw ,
1033
1080
** kwargs ,
1034
1081
)
1082
+ result = backend_response .response
1083
+
1035
1084
try :
1036
1085
if result .headers .get ("Content-Type" , None ) == "application/json" :
1037
1086
json_result = result .json ()
@@ -1075,7 +1124,7 @@ def http_put(
1075
1124
query_data = query_data or {}
1076
1125
post_data = post_data or {}
1077
1126
1078
- result = self .http_request (
1127
+ backend_response = self .http_request (
1079
1128
"put" ,
1080
1129
path ,
1081
1130
query_data = query_data ,
@@ -1085,7 +1134,7 @@ def http_put(
1085
1134
** kwargs ,
1086
1135
)
1087
1136
try :
1088
- json_result = result .json ()
1137
+ json_result = backend_response .json ()
1089
1138
if TYPE_CHECKING :
1090
1139
assert isinstance (json_result , dict )
1091
1140
return json_result
@@ -1124,7 +1173,7 @@ def http_patch(
1124
1173
query_data = query_data or {}
1125
1174
post_data = post_data or {}
1126
1175
1127
- result = self .http_request (
1176
+ backend_response = self .http_request (
1128
1177
"patch" ,
1129
1178
path ,
1130
1179
query_data = query_data ,
@@ -1133,7 +1182,7 @@ def http_patch(
1133
1182
** kwargs ,
1134
1183
)
1135
1184
try :
1136
- json_result = result .json ()
1185
+ json_result = backend_response .json ()
1137
1186
if TYPE_CHECKING :
1138
1187
assert isinstance (json_result , dict )
1139
1188
return json_result
@@ -1156,7 +1205,8 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
1156
1205
Raises:
1157
1206
GitlabHttpError: When the return code is not 2xx
1158
1207
"""
1159
- return self .http_request ("delete" , path , ** kwargs )
1208
+ backend_response = self .backend_request ("delete" , path , ** kwargs )
1209
+ return backend_response .response
1160
1210
1161
1211
@gitlab .exceptions .on_http_error (gitlab .exceptions .GitlabSearchError )
1162
1212
def search (
@@ -1210,7 +1260,11 @@ def _query(
1210
1260
self , url : str , query_data : Optional [Dict [str , Any ]] = None , ** kwargs : Any
1211
1261
) -> None :
1212
1262
query_data = query_data or {}
1213
- result = self ._gl .http_request ("get" , url , query_data = query_data , ** kwargs )
1263
+ backend_response = self ._gl .backend_request (
1264
+ "get" , url , query_data = query_data , ** kwargs
1265
+ )
1266
+ result = backend_response .response
1267
+
1214
1268
try :
1215
1269
next_url = result .links ["next" ]["url" ]
1216
1270
except KeyError :
0 commit comments