MCPcopy Index your code
hub / github.com/code-scan/Goal / New

Method New

Ghttp/http.go:74–103  ·  view source on GitHub ↗

新建一个请求

(method, urls string)

Source from the content-addressed store, hash-verified

72
73// 新建一个请求
74func (h *Http) New(method, urls string) *Http {
75 var err error
76 h.err = nil
77 h.Ctx, h.CtxCancel = context.WithCancel(context.Background())
78 h.HttpRequestUrl = urls
79 h.HttpRequestType = method
80 // 初始化http client 如果开启了session,则传入cookie jar
81 if h.HttpTransport == nil {
82 //log.Println("new transport")
83 h.HttpTransport = &transport
84 }
85 h.HttpClient = &http.Client{Transport: h.HttpTransport}
86
87 if h.isSession {
88 if h.Cookie == nil {
89 h.Cookie, _ = cookiejar.New(nil)
90 }
91 if h.HttpClient.Jar == nil {
92 h.HttpClient.Jar = h.Cookie
93 }
94 }
95
96 h.SetTimeOut(30)
97 h.IgnoreSSL()
98 h.HttpRequest, err = http.NewRequest(h.HttpRequestType, h.HttpRequestUrl, h.HttpBody)
99 h.HttpRequest.WithContext(h.Ctx)
100 h.err = err
101 return h
102 // return err
103}
104func (h *Http) SetTimeOut(t int) {
105 td := time.Duration(t)
106 h.HttpTransport.TLSHandshakeTimeout = td * time.Second

Callers 15

HeadMethod · 0.95
PostMethod · 0.95
GetMethod · 0.95
IPinfoFunction · 0.95
RunProxyFunction · 0.80
TestCookieFunction · 0.80
TestManyReqFunction · 0.80
GetResultMethod · 0.80
sendMethod · 0.80
GetResultMethod · 0.80
GetResultMethod · 0.80
CheckLoginMethod · 0.80

Calls 2

SetTimeOutMethod · 0.95
IgnoreSSLMethod · 0.95

Tested by 2

TestCookieFunction · 0.64
TestManyReqFunction · 0.64