Skip to content

add cli httpclient with support for proxy configuration #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 19, 2020
Prev Previous commit
Next Next commit
add httpclient roundtripper with proxy and user-agent
  • Loading branch information
hdiniz committed Apr 23, 2020
commit a383457f12643958ed922e12235ef5d5bbe0ca38
26 changes: 26 additions & 0 deletions httpclient/httpclient_transport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package httpclient

import "net/http"

type httpClientRoundTripper struct {
transport http.RoundTripper
config *Config
}

func newHTTPClientTransport(config *Config) http.RoundTripper {
proxy := http.ProxyURL(config.Proxy)

transport := &http.Transport{
Proxy: proxy,
}

return &httpClientRoundTripper{
transport: transport,
config: config,
}
}

func (h *httpClientRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Add("User-Agent", h.config.UserAgent)
return h.transport.RoundTrip(req)
}