-
Notifications
You must be signed in to change notification settings - Fork 132
Refactor codebase to use a unified http client #668
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ | |
| import pyarrow | ||
| except ImportError: | ||
| pyarrow = None | ||
| import requests | ||
| import json | ||
| import os | ||
| import decimal | ||
|
|
@@ -292,6 +291,7 @@ def read(self) -> Optional[OAuthToken]: | |
| auth_provider=self.session.auth_provider, | ||
| host_url=self.session.host, | ||
| batch_size=self.telemetry_batch_size, | ||
| http_client=self.session.http_client, | ||
|
Contributor
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. so we are not keeping different client for Telemetry ( I believe there is different retry behaviour for it ) |
||
| ) | ||
|
|
||
| self._telemetry_client = TelemetryClientFactory.get_telemetry_client( | ||
|
|
@@ -744,16 +744,20 @@ def _handle_staging_put( | |
| ) | ||
|
|
||
| with open(local_file, "rb") as fh: | ||
| r = requests.put(url=presigned_url, data=fh, headers=headers) | ||
| r = self.connection.session.http_client.request('PUT', presigned_url, body=fh.read(), headers=headers) | ||
|
||
| # Add compatibility attributes for urllib3 response | ||
| r.status_code = r.status | ||
| if hasattr(r, 'data'): | ||
| r.content = r.data | ||
| r.ok = r.status < 400 | ||
| r.text = r.data.decode() if r.data else "" | ||
|
|
||
| # fmt: off | ||
| # Design borrowed from: https://stackoverflow.com/a/2342589/5093960 | ||
|
|
||
| OK = requests.codes.ok # 200 | ||
| CREATED = requests.codes.created # 201 | ||
| ACCEPTED = requests.codes.accepted # 202 | ||
| NO_CONTENT = requests.codes.no_content # 204 | ||
|
|
||
| # HTTP status codes | ||
| OK = 200 | ||
| CREATED = 201 | ||
| ACCEPTED = 202 | ||
| NO_CONTENT = 204 | ||
| # fmt: on | ||
|
|
||
| if r.status_code not in [OK, CREATED, NO_CONTENT, ACCEPTED]: | ||
|
|
@@ -783,7 +787,13 @@ def _handle_staging_get( | |
| session_id_hex=self.connection.get_session_id_hex(), | ||
| ) | ||
|
|
||
| r = requests.get(url=presigned_url, headers=headers) | ||
| r = self.connection.session.http_client.request('GET', presigned_url, headers=headers) | ||
| # Add compatibility attributes for urllib3 response | ||
| r.status_code = r.status | ||
| if hasattr(r, 'data'): | ||
| r.content = r.data | ||
| r.ok = r.status < 400 | ||
| r.text = r.data.decode() if r.data else "" | ||
|
|
||
| # response.ok verifies the status code is not between 400-600. | ||
| # Any 2xx or 3xx will evaluate r.ok == True | ||
|
|
@@ -802,7 +812,13 @@ def _handle_staging_remove( | |
| ): | ||
| """Make an HTTP DELETE request to the presigned_url""" | ||
|
|
||
| r = requests.delete(url=presigned_url, headers=headers) | ||
| r = self.connection.session.http_client.request('DELETE', presigned_url, headers=headers) | ||
| # Add compatibility attributes for urllib3 response | ||
| r.status_code = r.status | ||
| if hasattr(r, 'data'): | ||
| r.content = r.data | ||
| r.ok = r.status < 400 | ||
| r.text = r.data.decode() if r.data else "" | ||
|
|
||
| if not r.ok: | ||
| raise OperationalError( | ||
|
|
||
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.
How is a static method using class http_client ?