Skip to content

Add tests verifying custom HTTPClient with proxy configuration#323

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-httpclient-proxy-usage
Draft

Add tests verifying custom HTTPClient with proxy configuration#323
Copilot wants to merge 5 commits intomainfrom
copilot/fix-httpclient-proxy-usage

Conversation

Copy link

Copilot AI commented Feb 23, 2026

Issue claimed custom HTTPClient with proxy settings is ignored when passed via ClientParams. Investigation confirms this is not a bug - the implementation correctly uses custom HTTPClient throughout the request chain.

Changes

Added comprehensive test coverage (3 test files, ~400 LOC):

Unit tests (client/custom_httpclient_test.go)

  • Custom transport invocation during requests
  • HTTPClient flow through RequestHandler
  • Default HTTPClient lazy initialization

Integration tests (twilio_custom_httpclient_integration_test.go)

  • Full RestClient → RequestHandler → Client chain preservation
  • SetTimeout behavior with custom HTTPClient

Proxy scenario tests (twilio_proxy_test.go)

  • Exact issue scenario: http.ProxyURL configuration
  • Proxy function invocation verification
  • Proxy URL preservation through client chain

Example Usage (from tests)

// Pattern from official docs - works correctly
httpClient := &http.Client{
    Transport: &http.Transport{
        Proxy: http.ProxyURL(proxyURL),
    },
}

baseClient := &client.Client{
    Credentials: client.NewCredentials(accountSid, authToken),
    HTTPClient:  httpClient,  // ✓ Properly used for all requests
}
baseClient.SetAccountSid(accountSid)

twilioClient := twilio.NewRestClientWithParams(twilio.ClientParams{
    Client: baseClient,
})

No production code changes required. Tests serve as regression protection and usage documentation.

Warning

GitHub's Secret Scanning detected potential secrets in the added content. We attempted to remediate the issue by updating the code or redacting.

Original prompt

This section details on the original issue you should resolve

<issue_title>Custom HTTPClient with proxy is ignored when passed via ClientParams</issue_title>
<issue_description>When providing a custom *client.Client with a configured HTTPClient (e.g., with proxy settings) via twilio.NewRestClientWithParams(), the SDK ignores the custom HTTPClient for actual API requests.

Steps to reproduce

// Create http.Client with proxy
httpClient := &http.Client{
    Transport: &http.Transport{
        Proxy: http.ProxyURL(proxyURL),
    },
}

// Create Twilio client with custom HTTPClient
baseClient := &client.Client{
    Credentials: client.NewCredentials(accountSid, authToken),
    HTTPClient:  httpClient,
}
baseClient.SetAccountSid(accountSid)

twilioClient := twilio.NewRestClientWithParams(twilio.ClientParams{
    Client: baseClient,
})

// Make API call - this SHOULD go through proxy but doesn't
twilioClient.Api.FetchBalance(&api.FetchBalanceParams{})

Expected behavior

All HTTP requests should use the provided HTTPClient with proxy configuration.

Actual behavior

Requests bypass the custom HTTPClient and go directly to Twilio API without proxy.

Root cause

In client/client.go, the SendRequest method calls c.doWithErr(req) at line 220. When a custom client implementing BaseClient interface is passed, the SDK's internal request flow doesn't properly use the HTTPClient field from the provided client.

Workaround

Create a wrapper type that implements BaseClient and overrides SendRequest to directly use HTTPClient.Do(req).

Environment

  • twilio-go version: v1.25.1 (also verified in v1.28.8 - same issue)
  • Go version: 1.21+

Note

The official documentation shows this exact pattern for proxy configuration, but it doesn't work as documented.
</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 4 commits February 23, 2026 06:40
Tests verify that custom HTTPClient with proxy settings is properly used
through both direct client.SendRequest and RequestHandler.Get paths.

Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com>
Tests verify custom HTTPClient flows correctly through the full
RestClient -> RequestHandler -> Client chain and that SetTimeout
preserves the custom HTTPClient instance.

Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com>
Tests verify the exact scenario from the issue description:
- Custom HTTPClient with http.ProxyURL is properly configured
- Proxy function is actually called when making requests
- Proxy URL configuration is preserved through the client chain

All tests pass, confirming the reported issue does not exist
in the current codebase.

Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com>
Add explicit verification that HTTPClient is nil before first use
when using default client creation (lazy initialization pattern).

Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix custom HTTPClient with proxy not used in API requests Add tests verifying custom HTTPClient with proxy configuration Feb 23, 2026
Copilot AI requested a review from manisha1997 February 23, 2026 06:49
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.

Custom HTTPClient with proxy is ignored when passed via ClientParams

2 participants