-
Notifications
You must be signed in to change notification settings - Fork 9
/
socks5_client_test.go
61 lines (53 loc) · 1.15 KB
/
socks5_client_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package socks
import (
"net"
"net/http"
"net/http/httputil"
"testing"
)
const (
TestSocks5ServerAddress = "127.0.0.1:8001"
TestSocks5TargetDomain = "www.baidu.com"
)
func TestSocks5Client(t *testing.T) {
listener, err := net.Listen("tcp", TestSocks5ServerAddress)
if err != nil {
t.Fatal(err)
}
defer listener.Close()
go func() {
server, err := NewSocks5Server(Direct)
if err != nil {
t.Fatal(err)
}
server.Serve(listener)
}()
client, err := NewSocks5Client("tcp", TestSocks5ServerAddress, "", "", Direct)
if err != nil {
t.Fatal(err)
}
conn, err := client.Dial("tcp", TestSocks5TargetDomain+":80")
if err != nil {
t.Fatal(err)
}
t.Log("client.Dial succeeded")
httpClient := httputil.NewClientConn(conn, nil)
if err != nil {
conn.Close()
t.Fatal(err)
}
defer httpClient.Close()
request, err := http.NewRequest("GET", "/", nil)
if err != nil {
t.Fatal(err)
}
resp, err := httpClient.Do(request)
if err != nil {
t.Fatal(err)
}
data, err := httputil.DumpResponse(resp, true)
if err != nil {
t.Fatal(err)
}
t.Log("socks5 HTTP Get:", string(data))
}