gojek / heimdall

An enhanced HTTP client for Go
http://gojek.tech
Apache License 2.0
2.63k stars 214 forks source link

No way to parse proxies / http transport with hystrix client? #102

Open JonathanSlowwe opened 3 years ago

JonathanSlowwe commented 3 years ago

This is my hystrix client:


client := hystrix.NewClient(
    hystrix.WithHTTPTimeout(1*time.Millisecond),
    hystrix.WithCommandName("request"),
    hystrix.WithHystrixTimeout(10*time.Millisecond),
    hystrix.WithMaxConcurrentRequests(600),
    hystrix.WithErrorPercentThreshold(20),
)

I cant seem a way to parse in proxies so it sends requests from different IP addresses. This is how I would do it in net/http:


proxy := "http://" + selectProxy proxyURL, _ := url.Parse(proxy) transport := &http.Transport{Proxy: http.ProxyURL(proxyURL)}

client := &http.Client{Transport: transport, Timeout: 5 * time.Second}


Any help or tips to parse in the http transport/ dial or proxies with the hystrix client would be appreciated.

markphelps commented 3 years ago

Couldn't you use the Custom HTTP client functionality like so?

type myHTTPClient struct {
    client http.Client
}

func (c *myHTTPClient) Do(request *http.Request) (*http.Response, error) {
    return c.client.Do(request)
}

proxy := "http://" + selectProxy
proxyURL, _ := url.Parse(proxy)
transport := &http.Transport{Proxy: http.ProxyURL(proxyURL)}

httpclient.NewClient(httpclient.WithHTTPClient(&myHTTPClient{client: &http.Client{Transport: transport, Timeout: 5 * time.Second}}))