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

RESTClient: pass environment settings to requests.Session.send #1452

Merged
merged 1 commit into from
Jun 10, 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
6 changes: 5 additions & 1 deletion dlt/sources/helpers/rest_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ def _send_request(self, request: Request) -> Response:

prepared_request = self.session.prepare_request(request)

return self.session.send(prepared_request)
send_kwargs = self.session.merge_environment_settings(
prepared_request.url, {}, None, None, None
)

return self.session.send(prepared_request, **send_kwargs)

def request(self, path: str = "", method: HTTPMethod = "GET", **kwargs: Any) -> Response:
prepared_request = self._create_request(
Expand Down
14 changes: 14 additions & 0 deletions tests/sources/helpers/rest_client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,17 @@ def __call__(self, request: PreparedRequest) -> PreparedRequest:
assert_pagination(pages_list)

assert pages_list[0].response.request.headers["Authorization"] == "Bearer test-token"

def test_send_request_allows_ca_bundle(self, mocker, rest_client):
mocker.patch.dict(os.environ, {"REQUESTS_CA_BUNDLE": "/path/to/some/ca-bundle"})

_send = rest_client.session.send

def _fake_send(*args, **kwargs):
assert kwargs["verify"] == "/path/to/some/ca-bundle"
return _send(*args, **kwargs)

rest_client.session.send = _fake_send

result = rest_client.get("/posts/1")
assert result.status_code == 200
Loading