Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parameter to control redirects #22

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rolo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def merge_environment_settings(self, url, proxies, stream, verify, *args, **kwar

class SimpleRequestsClient(HttpClient):
session: requests.Session
follow_redirects: bool

def __init__(self, session: requests.Session = None):
def __init__(self, session: requests.Session = None, follow_redirects: bool = True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we kept the parameter specific to requests, i would have kept the original name of allow_redirects, so it's consistent with the requests library :-) though follow_redirects is the better name to generalize if we added it to all client implementations

self.session = session or _VerifyRespectingSession()
self.follow_redirects = follow_redirects

@staticmethod
def _get_destination_url(request: Request, server: str | None = None) -> str:
Expand All @@ -80,6 +82,7 @@ def request(self, request: Request, server: str | None = None) -> Response:

:param request: the request to perform
:param server: the URL to send the request to, which defaults to the host component of the original Request.
:param allow_redirects: allow the request to follow redirects
:return: the response.
"""

Expand All @@ -106,6 +109,7 @@ def request(self, request: Request, server: str | None = None) -> Response:
headers=headers,
data=restore_payload(request),
stream=True,
allow_redirects=self.follow_redirects,
)

if request.method == "HEAD":
Expand Down
Loading