PyRIT
PyRIT copied to clipboard
FEAT extend http target to allow custom http client
Allow injection of pre-configured httpx client in HTTPTarget
Changes
- Added alternative constructor
with_clientto allow direct injection of pre-configured httpx.AsyncClient instances - Modified
__init__to accept an optional_clientparameter - Updated
send_prompt_asyncto 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.