Skip to content
Closed
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
3 changes: 2 additions & 1 deletion haystack/components/fetchers/link_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def __init__(
self.retry_attempts = retry_attempts
self.timeout = timeout
self.http2 = http2
self.client_kwargs = client_kwargs or {}
# Copy so that applying the defaults below does not change the caller's dictionary.
self.client_kwargs = dict(client_kwargs or {})
self.request_headers = request_headers or {}

# Configure default client settings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
`LinkContentFetcher` no longer adds its `timeout` and `follow_redirects` defaults to the `client_kwargs`
dictionary passed by the caller. The dictionary is copied before the defaults are applied, so sharing one
HTTP-client configuration between components is safe.
10 changes: 10 additions & 0 deletions test/components/fetchers/test_link_content_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def test_init_with_params(self):
assert "verify" in fetcher.client_kwargs
assert fetcher.client_kwargs["verify"] is False

def test_init_does_not_mutate_client_kwargs(self):
"""The caller's dictionary must not pick up the component's defaults."""
client_kwargs = {"headers": {"X-Request-ID": "example"}}

fetcher = LinkContentFetcher(timeout=10, client_kwargs=client_kwargs)

assert client_kwargs == {"headers": {"X-Request-ID": "example"}}
assert fetcher.client_kwargs["timeout"] == 10
assert fetcher.client_kwargs["follow_redirects"] is True

def test_run_text(self):
"""Test fetching text content"""
correct_response = b"Example test response"
Expand Down