-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.go
45 lines (36 loc) · 1.18 KB
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Package requestor contains the methods to make HTTP requests to different endpoints
package requestor
import (
"net/http"
"net/url"
)
// SetHTTPProxy sets a HTTP proxy to the transport, proxyURL is a required parameter, but username and password
// is optional parameters. Proxy URL should be of format IP:PORT or HOSTNAME:PORT
func (c *Client) SetHTTPProxy(proxyURL, username, password string) {
proxyConfig := &url.URL{
Scheme: "http",
Host: proxyURL,
}
if username != "" && password != "" {
proxyConfig.User = url.UserPassword(username, password)
}
transport := &http.Transport{
Proxy: http.ProxyURL(proxyConfig),
}
c.transport = transport
}
// SetHTTPSProxy sets a HTTP proxy to the transport, proxyURL is a required parameter, but username and password
// is optional parameters. Proxy URL should be of format IP:PORT or HOSTNAME:PORT
func (c *Client) SetHTTPSProxy(proxyURL, username, password string) {
proxyConfig := &url.URL{
Scheme: "https",
Host: proxyURL,
}
if username != "" && password != "" {
proxyConfig.User = url.UserPassword(username, password)
}
transport := &http.Transport{
Proxy: http.ProxyURL(proxyConfig),
}
c.transport = transport
}