From 2c6b5d3428bbe1d2627816ed48b386d79d57163d Mon Sep 17 00:00:00 2001 From: Brianna Becker Date: Thu, 11 Sep 2025 14:07:43 +0200 Subject: [PATCH 1/3] feat: optional proxy support for http_requests --- src/strands_tools/http_request.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/strands_tools/http_request.py b/src/strands_tools/http_request.py index 884ff214..8b1e3795 100644 --- a/src/strands_tools/http_request.py +++ b/src/strands_tools/http_request.py @@ -52,7 +52,7 @@ "JWT, AWS SigV4, Digest auth, and enterprise authentication patterns. Automatically reads tokens from " "environment variables (GITHUB_TOKEN, GITLAB_TOKEN, AWS credentials, etc.) when auth_env_var is specified. " "Use environment(action='list') to view available variables. Includes session management, metrics, " - "streaming support, cookie handling, redirect control, and optional HTML to markdown conversion." + "streaming support, cookie handling, redirect control, proxy support, and optional HTML to markdown conversion." ), "inputSchema": { "json": { @@ -178,6 +178,15 @@ "expiry": {"type": "integer"}, }, }, + "proxies": { + "type": "object", + "description": "Dictionary mapping protocol or protocol and hostname to the URL of the proxy.", + "properties": { + "http": {"type": "string"}, + "https": {"type": "string"}, + "ftp": {"type": "string"}, + }, + }, }, "required": ["method", "url"], } @@ -747,6 +756,7 @@ def http_request(tool: ToolUse, **kwargs: Any) -> ToolResult: "verify": verify, "auth": auth, "allow_redirects": tool_input.get("allow_redirects", True), + "proxies": tool_input.get("proxies", None), } # Set max_redirects if specified From e9a497b8ff96564519891fabe83aa0eb653ee60d Mon Sep 17 00:00:00 2001 From: Brianna Becker Date: Thu, 11 Sep 2025 14:20:59 +0200 Subject: [PATCH 2/3] test: add test for http_request optional proxy support --- tests/test_http_request.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_http_request.py b/tests/test_http_request.py index 5ddf9d12..e00105a3 100644 --- a/tests/test_http_request.py +++ b/tests/test_http_request.py @@ -1045,3 +1045,49 @@ def test_markdown_conversion_non_html(): result_text = extract_result_text(result) assert "Status Code: 200" in result_text assert '"message": "hello"' in result_text # Should still be JSON (no conversion for non-HTML) + + +def test_proxy_support(): + """Test HTTP proxy support functionality.""" + tool_use = { + "toolUseId": "test-proxy-id", + "input": { + "method": "GET", + "url": "https://example.com/api/proxy-test", + "proxies": {"https": "https://proxy.example.com:8080"}, + }, + } + + # Mock the session.request method to capture the proxies parameter + with ( + patch("strands_tools.http_request.get_user_input") as mock_input, + patch("requests.Session.request") as mock_request, + ): + # Configure mock response + mock_response = MagicMock() + mock_response.status_code = 200 + mock_response.text = '{"status": "success via proxy"}' + mock_response.content = b'{"status": "success via proxy"}' + mock_response.headers = {"Content-Type": "application/json"} + mock_response.history = [] + mock_response.url = "https://example.com/api/proxy-test" + mock_response.request = MagicMock() + mock_response.request.body = None + mock_request.return_value = mock_response + + # Mock user input + mock_input.return_value = "y" + + # Call the function + result = http_request.http_request(tool=tool_use) + + # Verify the proxy was actually passed to requests + assert mock_request.called + call_kwargs = mock_request.call_args[1] + assert "proxies" in call_kwargs + assert call_kwargs["proxies"] == {"https": "https://proxy.example.com:8080"} + + # Verify the result + assert result["status"] == "success" + result_text = extract_result_text(result) + assert "Status Code: 200" in result_text From e3429aa21c07c6a943626f61a4318136039c4dad Mon Sep 17 00:00:00 2001 From: Brianna Becker Date: Thu, 11 Sep 2025 14:23:49 +0200 Subject: [PATCH 3/3] docs: http_request doc string update with proxy example --- src/strands_tools/http_request.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/strands_tools/http_request.py b/src/strands_tools/http_request.py index 8b1e3795..a017e598 100644 --- a/src/strands_tools/http_request.py +++ b/src/strands_tools/http_request.py @@ -617,6 +617,15 @@ def http_request(tool: ToolUse, **kwargs: Any) -> ToolResult: ) ``` + 7. Using proxy: + ```python + http_request( + method="GET", + url="https://example.com/api", + proxies={"https": "https://proxy.example.com:8080"}, + ) + ``` + Environment Variables: - Authentication tokens are read from environment when auth_env_var is specified - AWS credentials are automatically loaded from environment variables or credentials file