-
-
Notifications
You must be signed in to change notification settings - Fork 527
store response headers at each requests #308
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,7 @@ def __init__( | |
| self._user_id = None | ||
| self._user_agent = user_agent or 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_6_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15' | ||
| self._act_as = None | ||
| self._response_headers = None | ||
|
|
||
| self.gql = GQLClient(self) | ||
| self.v11 = V11Client(self) | ||
|
|
@@ -149,6 +150,8 @@ async def request( | |
| response = await self.http.request(method, url, headers=headers, **kwargs) | ||
| self._remove_duplicate_ct0_cookie() | ||
|
|
||
| self._response_headers = response.headers | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Assignment of response headers to a shared state may be problematic in concurrent scenarios. If the client is expected to handle concurrent requests, consider returning response headers with each request's result rather than storing them in a mutable instance variable. This can prevent potential race conditions. Suggested implementation: # Removed setting shared response headers to avoid race conditions. return response_data, response.headersEnsure that any callers of this function are updated to handle a tuple (data, headers) rather than expecting just the response data. |
||
|
|
||
| try: | ||
| response_data = response.json() | ||
| except json.decoder.JSONDecodeError: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Initialization of _response_headers could lead to shared mutable state issues.
Since _response_headers is an instance variable, if the client is used concurrently, multiple requests may overwrite its value. Evaluate whether this state should be tied to individual requests or managed in a thread-safe manner.
Suggested implementation:
Make sure any subsequent code in this function or other functions that previously relied on self._response_headers now uses the local variable (response_headers) or otherwise has been refactored to access the response headers as needed.