Skip to content

Commit a383457

Browse files
committed
add httpclient roundtripper with proxy and user-agent
1 parent bc26218 commit a383457

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

httpclient/httpclient_transport.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package httpclient
2+
3+
import "net/http"
4+
5+
type httpClientRoundTripper struct {
6+
transport http.RoundTripper
7+
config *Config
8+
}
9+
10+
func newHTTPClientTransport(config *Config) http.RoundTripper {
11+
proxy := http.ProxyURL(config.Proxy)
12+
13+
transport := &http.Transport{
14+
Proxy: proxy,
15+
}
16+
17+
return &httpClientRoundTripper{
18+
transport: transport,
19+
config: config,
20+
}
21+
}
22+
23+
func (h *httpClientRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
24+
req.Header.Add("User-Agent", h.config.UserAgent)
25+
return h.transport.RoundTrip(req)
26+
}

0 commit comments

Comments
 (0)