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

Added request syntax compatibility #18

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion noble_tls/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def build_response(res: Dict[str, Any], res_cookies) -> Response:
response.text = res.get("body", "") # Default to empty string if body is not provided.

# Process headers, ensuring single values are not wrapped in a list.
response_headers = {}
response_headers = CaseInsensitiveDict()
for key, value in res.get("headers", {}).items():
response_headers[key] = value[0] if len(value) == 1 else value
response.headers = response_headers
Expand Down
18 changes: 15 additions & 3 deletions noble_tls/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ def __init__(
# loop
self.loop = asyncio.get_event_loop()

@property
def timeout(self):
return self.timeout_seconds

@timeout.setter
def timeout(self, seconds):
self.timeout_seconds = seconds

async def execute_request(
self,
method: str,
Expand All @@ -279,8 +287,15 @@ async def execute_request(
allow_redirects: Optional[bool] = True,
insecure_skip_verify: Optional[bool] = False,
timeout_seconds: Optional[int] = None,
timeout: Optional[int] = None,
proxy: Optional[dict] = None # Optional[dict[str, str]]
):

# --- Timeout --------------------------------------------------------------------------------------------------
# maximum time to wait for a response
timeout_seconds = timeout or timeout_seconds or self.timeout_seconds
del timeout # deleting alias to stop further usage

# --- History ------------------------------------------------------------------------------------------------------
history = [] # Initialize an empty list to store the history of responses

Expand Down Expand Up @@ -345,10 +360,7 @@ async def execute_request(
else:
proxy = ""

# --- Timeout --------------------------------------------------------------------------------------------------
# maximum time to wait

timeout_seconds = timeout_seconds or self.timeout_seconds

while True:
# --- Request --------------------------------------------------------------------------------------------------
Expand Down