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.