Skip to content

Commit

Permalink
Pass environment settings to requests.Session.send, fixes #1447
Browse files Browse the repository at this point in the history
  • Loading branch information
burnash authored Jun 10, 2024
1 parent 3609757 commit 2406636
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit 2406636

Please sign in to comment.