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

FEAT extend http target to allow custom http client #804

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ayeganov
Copy link
Contributor

Allow injection of pre-configured httpx client in HTTPTarget

Changes

  • Added alternative constructor with_client to allow direct injection of pre-configured httpx.AsyncClient instances
  • Modified __init__ to accept an optional _client parameter
  • Updated send_prompt_async to handle both injected and auto-created clients
  • Maintained full backward compatibility with existing usage

Why

This change enables more flexible configuration of the HTTP client used by HTTPTarget. Users can now:

  • Pre-configure custom timeout settings, proxies, or certificate handling
  • Reuse client connections across multiple HTTPTarget instances
  • Better control client lifecycle when needed
  • Inject mock clients for testing

Example Usage

# Original usage remains unchanged
target1 = HTTPTarget(http_request="...", use_tls=True)

# New usage with custom client
client = httpx.AsyncClient(timeout=30.0, verify=False)
target2 = HTTPTarget.with_client(client=client, http_request="...")

Description

Tests and Documentation

Added new test test_http_target_with_injected_client.

@romanlutz romanlutz changed the title feat: extend http target to allow custom http client FEAT extend http target to allow custom http client Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants