Skip to content

Commit cfc42d2

Browse files
authored
Merge pull request #1392 from bbatliner/patch-1
Improvements to HTTP requests
2 parents 4f79dff + b9ecc9a commit cfc42d2

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

gitlab/client.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ def http_request(
451451
post_data: Optional[Dict[str, Any]] = None,
452452
streamed: bool = False,
453453
files: Optional[Dict[str, Any]] = None,
454+
timeout: Optional[float] = None,
455+
obey_rate_limit: bool = True,
456+
retry_transient_errors: bool = False,
457+
max_retries: int = 10,
454458
**kwargs: Any,
455459
) -> requests.Response:
456460
"""Make an HTTP request to the Gitlab server.
@@ -465,6 +469,14 @@ def http_request(
465469
json)
466470
streamed (bool): Whether the data should be streamed
467471
files (dict): The files to send to the server
472+
timeout (float): The timeout, in seconds, for the request
473+
obey_rate_limit (bool): Whether to obey 429 Too Many Request
474+
responses. Defaults to True.
475+
retry_transient_errors (bool): Whether to retry after 500, 502,
476+
503, or 504 responses. Defaults
477+
to False.
478+
max_retries (int): Max retries after 429 or transient errors,
479+
set to -1 to retry forever. Defaults to 10.
468480
**kwargs: Extra options to send to the server (e.g. sudo)
469481
470482
Returns:
@@ -496,9 +508,10 @@ def http_request(
496508
opts = self._get_session_opts(content_type="application/json")
497509

498510
verify = opts.pop("verify")
499-
timeout = opts.pop("timeout")
511+
opts_timeout = opts.pop("timeout")
500512
# If timeout was passed into kwargs, allow it to override the default
501-
timeout = kwargs.get("timeout", timeout)
513+
if timeout is None:
514+
timeout = opts_timeout
502515

503516
# We need to deal with json vs. data when uploading files
504517
if files:
@@ -532,15 +545,7 @@ def http_request(
532545
prepped.url, {}, streamed, verify, None
533546
)
534547

535-
# obey the rate limit by default
536-
obey_rate_limit = kwargs.get("obey_rate_limit", True)
537-
# do not retry transient errors by default
538-
retry_transient_errors = kwargs.get("retry_transient_errors", False)
539-
540-
# set max_retries to 10 by default, disable by setting it to -1
541-
max_retries = kwargs.get("max_retries", 10)
542548
cur_retries = 0
543-
544549
while True:
545550
result = self.session.send(prepped, timeout=timeout, **settings)
546551

@@ -827,6 +832,9 @@ def __init__(
827832
self._query(url, query_data, **self._kwargs)
828833
self._get_next = get_next
829834

835+
# Remove query_parameters from kwargs, which are saved via the `next` URL
836+
self._kwargs.pop("query_parameters", None)
837+
830838
def _query(
831839
self, url: str, query_data: Optional[Dict[str, Any]] = None, **kwargs: Any
832840
) -> None:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy