Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ee03a1c7b | ||
|
|
a68be94c7f | ||
|
|
4eb213aa6d |
@@ -246,3 +246,9 @@ func (ses *Session) Options(url string) *Workflow {
|
|||||||
wf.SetURL(url)
|
wf.SetURL(url)
|
||||||
return wf
|
return wf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseIdleConnections closes the idle connections that a session client may make use of
|
||||||
|
// 从levigross/grequests 借鉴
|
||||||
|
func (ses *Session) CloseIdleConnections() {
|
||||||
|
ses.client.Transport.(*http.Transport).CloseIdleConnections()
|
||||||
|
}
|
||||||
|
|||||||
40
workflow.go
40
workflow.go
@@ -147,13 +147,13 @@ func (wf *Workflow) SetURLPath(path []string) *Workflow {
|
|||||||
return wf
|
return wf
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetURLRawPath 设置Path参数
|
// SetURLRawPath 设置Pa晚上参数
|
||||||
func (wf *Workflow) SetURLRawPath(path string) *Workflow {
|
func (wf *Workflow) SetURLRawPath(path string) *Workflow {
|
||||||
wf.ParsedURL.Path = path
|
wf.ParsedURL.Path = path
|
||||||
return wf
|
return wf
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBodyParams 参数设置
|
// SetBodyParams 参数设晚上
|
||||||
func (wf *Workflow) SetBodyParams(params ...interface{}) *Workflow {
|
func (wf *Workflow) SetBodyParams(params ...interface{}) *Workflow {
|
||||||
if params == nil {
|
if params == nil {
|
||||||
return wf
|
return wf
|
||||||
@@ -194,17 +194,8 @@ func (wf *Workflow) SetBodyParams(params ...interface{}) *Workflow {
|
|||||||
return wf
|
return wf
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute 执行
|
// setHeaderRequest 设置request的头
|
||||||
func (wf *Workflow) Execute() (*Response, error) {
|
func setHeaderRequest(req *http.Request, wf *Workflow) {
|
||||||
|
|
||||||
req := buildBodyRequest(wf.Method, wf.GetStringURL(), wf.Body)
|
|
||||||
|
|
||||||
if wf.Cookies != nil {
|
|
||||||
for _, c := range wf.Cookies {
|
|
||||||
req.AddCookie(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set := make(map[string]map[string]int)
|
set := make(map[string]map[string]int)
|
||||||
for key, values := range wf.session.Header {
|
for key, values := range wf.session.Header {
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
@@ -233,6 +224,29 @@ func (wf *Workflow) Execute() (*Response, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// setHeaderRequest 设置request的临时Cookie, 永久需要在session上设置cookie
|
||||||
|
func setTempCookieRequest(req *http.Request, wf *Workflow) {
|
||||||
|
if wf.Cookies != nil {
|
||||||
|
for _, c := range wf.Cookies {
|
||||||
|
req.AddCookie(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute 执行
|
||||||
|
func (wf *Workflow) Execute() (*Response, error) {
|
||||||
|
|
||||||
|
req := buildBodyRequest(wf.Method, wf.GetStringURL(), wf.Body)
|
||||||
|
|
||||||
|
setHeaderRequest(req, wf)
|
||||||
|
setTempCookieRequest(req, wf)
|
||||||
|
|
||||||
|
if wf.session.auth != nil {
|
||||||
|
req.SetBasicAuth(wf.session.auth.User, wf.session.auth.Password)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := wf.session.client.Do(req)
|
resp, err := wf.session.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user