Skip to content

Commit

Permalink
refactor: move the request call to the backend (#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmilbaum committed Dec 10, 2022
1 parent 63cf4e4 commit 283e7cc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gitlab/client.py
Expand Up @@ -752,7 +752,7 @@ def http_request(
cur_retries = 0
while True:
try:
result = self.session.request(
result = self.http_backend.http_request(
method=verb,
url=url,
json=json,
Expand Down
43 changes: 42 additions & 1 deletion 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:
Expand All @@ -10,3 +11,43 @@ def __init__(self, session: Optional[requests.Session] = None) -> None:
@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
)

0 comments on commit 283e7cc

Please sign in to comment.