-
Notifications
You must be signed in to change notification settings - Fork 1
/
proxy_test.go
46 lines (39 loc) · 1013 Bytes
/
proxy_test.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
46
package gota
import (
"net/url"
"os"
"testing"
"golang.org/x/net/proxy"
)
func TestHttpProxy(t *testing.T) {
httpProxyEnv := os.Getenv("http_proxy")
if httpProxyEnv == "" {
t.Log("Error http_proxy environment variable.")
return
}
httpProxyURI, _ := url.Parse(httpProxyEnv)
httpDialer, _ := proxy.FromURL(httpProxyURI, Direct)
conn, err := httpDialer.Dial("tcp", "google.com:80")
if err != nil {
t.Errorf("Create http tunnel error: %+v", err)
return
}
t.Logf("Create http tunnel OK: %+v\n", conn)
conn.Close()
}
func TestHttpsProxy(t *testing.T) {
httpsProxyEnv := os.Getenv("https_proxy")
if httpsProxyEnv == "" {
t.Log("Error https_proxy environment variable.")
return
}
httpsProxyURI, _ := url.Parse(httpsProxyEnv)
httpsDialer, _ := proxy.FromURL(httpsProxyURI, HTTPSDialer)
conn, err := httpsDialer.Dial("tcp", "google.com:443")
if err != nil {
t.Errorf("Create https tunnel error: %+v", err)
return
}
t.Logf("Create https tunnel OK: %+v\n", conn)
conn.Close()
}