-
Notifications
You must be signed in to change notification settings - Fork 9
/
http_test.go
157 lines (123 loc) · 3.38 KB
/
http_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package spider
import (
"bytes"
"testing"
"github.com/PuerkitoBio/goquery"
"github.com/x-funs/go-fun"
)
func TestHttpGetCharsetLang(t *testing.T) {
var urlStrs = []string{
// "http://suosi.com.cn",
// "https://www.163.com",
// "https://english.news.cn",
// "https://jp.news.cn",
// "https://kr.news.cn",
// "https://www.donga.com/",
// "http://www.koreatimes.com/",
// "https://arabic.news.cn",
// "https://www.bbc.com",
// "http://government.ru",
"https://french.news.cn",
// "https://www.gouvernement.fr",
// "http://live.siammedia.org/",
// "http://hanoimoi.com.vn",
// "https://www.commerce.gov.mm",
// "https://sanmarg.in/",
// "https://www.rrdmyanmar.gov.mm",
// "http://english.eastday.com/",
// "http://jp.eastday.com/",
// "https://mn.cctv.com/",
}
for _, urlStr := range urlStrs {
resp, err := HttpGetResp(urlStr, nil, 30000)
t.Log(urlStr)
t.Log(err)
t.Log(resp.Success)
t.Log(resp.ContentLength)
t.Log(resp.Headers)
t.Log(resp.Charset)
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(resp.Body))
doc.Find(DefaultDocRemoveTags).Remove()
start := fun.Timestamp(true)
lang := Lang(doc, resp.Charset.Charset, true)
t.Log(lang)
t.Log(fun.Timestamp(true) - start)
}
}
func TestHttpGetCharsetLangURL(t *testing.T) {
var urlStrs = []string{
"https://marriott.co.kr",
}
for _, urlStr := range urlStrs {
resp, err := HttpGetResp(urlStr, nil, 30000)
t.Log(urlStr)
t.Log(err)
t.Log(resp.Success)
t.Log(resp.ContentLength)
t.Log(resp.Headers)
t.Log(resp.Charset)
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(resp.Body))
doc.Find(DefaultDocRemoveTags).Remove()
start := fun.Timestamp(true)
lang := Lang(doc, resp.Charset.Charset, true)
t.Log(lang)
t.Log(fun.Timestamp(true) - start)
}
}
func TestHttpGet(t *testing.T) {
var urlStr string
urlStr = "http://www.niuchaoqun.com"
// urlStr = "http://www.qq.com"
resp, err := HttpGetResp(urlStr, nil, 10000)
t.Log(urlStr)
t.Log(err)
t.Log(resp.Success)
t.Log(resp.ContentLength)
t.Log(resp.Headers)
t.Log(resp.Charset)
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(resp.Body))
doc.Find(DefaultDocRemoveTags).Remove()
lang := Lang(doc, resp.Charset.Charset, true)
t.Log(lang)
t.Log(fun.String(resp.Body))
}
func TestHttpGetContentType(t *testing.T) {
var urlStr string
urlStr = "https://mirrors.163.com/mysql/Downloads/MySQL-8.0/libmysqlclient-dev_8.0.27-1debian10_amd64.deb"
req := &HttpReq{
ForceTextContentType: true,
}
resp, err := HttpGetResp(urlStr, req, 10000)
t.Log(urlStr)
t.Log(err)
t.Log(resp.Success)
t.Log(resp.ContentLength)
t.Log(resp.Headers)
t.Log(resp.Charset)
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(resp.Body))
doc.Find(DefaultDocRemoveTags).Remove()
lang := Lang(doc, resp.Charset.Charset, true)
t.Log(lang)
t.Log(fun.String(resp.Body))
}
func TestHttpGetContentLength(t *testing.T) {
var urlStr string
urlStr = "http://suosi.com.cn"
req := &HttpReq{
HttpReq: &fun.HttpReq{
MaxContentLength: 1000,
},
}
resp, err := HttpGetResp(urlStr, req, 10000)
t.Log(urlStr)
t.Log(err)
t.Log(resp.Success)
t.Log(resp.ContentLength)
t.Log(resp.Headers)
t.Log(resp.Charset)
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(resp.Body))
doc.Find(DefaultDocRemoveTags).Remove()
lang := Lang(doc, resp.Charset.Charset, true)
t.Log(lang)
t.Log(fun.String(resp.Body))
}