Skip to content

Commit

Permalink
add parameter to control redirects in SimpleRequestsClient (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzon authored and thrau committed Aug 6, 2024
1 parent 1acdda5 commit 0aa35d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "rolo"
authors = [
{ name = "LocalStack Contributors", email = "[email protected]" }
]
version = "0.7.0"
version = "0.7.1"
description = "A Python framework for building HTTP-based server applications"
dependencies = [
"requests>=2.20",
Expand Down
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):
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

0 comments on commit 0aa35d8

Please sign in to comment.