summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorLiora Milbaum <liora@lmb.co.il>2022-12-10 15:06:11 +0200
committerGitHub <noreply@github.com>2022-12-10 13:06:11 +0000
commit283e7cc04ce61aa456be790a503ed64089a2c2b6 (patch)
tree6deda3bbc8b4f6e23ba8b212f4cd933453d640e6 /gitlab
parent63cf4e4fa81d6c5bf6cf74284321bc3ce19bab62 (diff)
downloadgitlab-283e7cc04ce61aa456be790a503ed64089a2c2b6.tar.gz
refactor: move the request call to the backend (#2413)
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/client.py2
-rw-r--r--gitlab/http_backends/requests_backend.py43
2 files changed, 43 insertions, 2 deletions
diff --git a/gitlab/client.py b/gitlab/client.py
index 5e1db0a..98f6905 100644
--- a/gitlab/client.py
+++ b/gitlab/client.py
@@ -752,7 +752,7 @@ class Gitlab:
cur_retries = 0
while True:
try:
- result = self.session.request(
+ result = self.http_backend.http_request(
method=verb,
url=url,
json=json,
diff --git a/gitlab/http_backends/requests_backend.py b/gitlab/http_backends/requests_backend.py
index eecbfdd..032597a 100644
--- a/gitlab/http_backends/requests_backend.py
+++ b/gitlab/http_backends/requests_backend.py
@@ -1,6 +1,7 @@
-from typing import Optional
+from typing import Any, Dict, Optional, Union
import requests
+from requests_toolbelt.multipart.encoder import MultipartEncoder # type: ignore
class RequestsBackend:
@@ -10,3 +11,43 @@ class RequestsBackend:
@property
def client(self) -> requests.Session:
return self._client
+
+ def http_request(
+ self,
+ method: str,
+ url: str,
+ json: Optional[Union[Dict[str, Any], bytes]] = None,
+ data: Optional[Union[Dict[str, Any], MultipartEncoder]] = None,
+ params: Optional[Any] = None,
+ timeout: Optional[float] = None,
+ verify: Optional[Union[bool, str]] = True,
+ stream: Optional[bool] = False,
+ **kwargs: Any
+ ) -> requests.Response:
+ """Make HTTP request
+
+ Args:
+ method: The HTTP method to call ('get', 'post', 'put', 'delete', etc.)
+ url: The full URL
+ data: The data to send to the server in the body of the request
+ json: Data to send in the body in json by default
+ timeout: The timeout, in seconds, for the request
+ verify: Whether SSL certificates should be validated. If
+ the value is a string, it is the path to a CA file used for
+ certificate validation.
+ stream: Whether the data should be streamed
+
+ Returns:
+ A requests Response object.
+ """
+ return self._client.request(
+ method=method,
+ url=url,
+ params=params,
+ data=data,
+ timeout=timeout,
+ stream=stream,
+ verify=verify,
+ json=json,
+ **kwargs
+ )