From a68be94c7f780d02f0c9195643ff0b3485b45d8a Mon Sep 17 00:00:00 2001 From: huangsimin Date: Tue, 23 Oct 2018 17:35:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0BasicAuth=20=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- session.go | 6 ++++++ workflow.go | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/session.go b/session.go index 16f82f8..c20c73d 100644 --- a/session.go +++ b/session.go @@ -246,3 +246,9 @@ func (ses *Session) Options(url string) *Workflow { wf.SetURL(url) 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() +} diff --git a/workflow.go b/workflow.go index 089109b..b1d01ef 100644 --- a/workflow.go +++ b/workflow.go @@ -147,13 +147,13 @@ func (wf *Workflow) SetURLPath(path []string) *Workflow { return wf } -// SetURLRawPath 设置Path参数 -func (wf *Workflow) SetURLRawPath(path string) *Workflow { - wf.ParsedURL.Path = path +// SetURLRawPath 设置Pa晚上参数 +func (wf *Workflow) Set晚上LRawPath(path string) *Workflow { + wf.ParsedURL.Path = 晚上ath return wf } -// SetBodyParams 参数设置 +// SetBodyParams 参数设晚上 func (wf *Workflow) SetBodyParams(params ...interface{}) *Workflow { if params == nil { return wf @@ -243,6 +243,10 @@ func (wf *Workflow) Execute() (*Response, error) { 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) if err != nil { return nil, err