accept iobody the type is string;

This commit is contained in:
huangsimin 2018-11-23 15:45:34 +08:00
parent a6217886dc
commit 84ae0a710e
2 changed files with 17 additions and 15 deletions

View File

@ -19,10 +19,12 @@ func buildBodyRequest(wf *Workflow) *http.Request {
switch wf.Body.GetIOBody().(type) {
case []byte:
bodybuf = bytes.NewBuffer(wf.Body.GetIOBody().([]byte))
case string:
bodybuf = bytes.NewBuffer([]byte(wf.Body.GetIOBody().(string)))
case *bytes.Buffer:
bodybuf = bytes.NewBuffer(wf.Body.GetIOBody().(*bytes.Buffer).Bytes())
default:
panic(errors.New("the type is not exist, type is" + reflect.TypeOf(wf.Body.GetIOBody()).String()))
panic(errors.New("the type is not exist, type is " + reflect.TypeOf(wf.Body.GetIOBody()).String()))
}
req, err = http.NewRequest(wf.Method, wf.GetRawURL(), bodybuf)
}

View File

@ -307,6 +307,13 @@ func (ses *Session) ClearCookies() {
ses.client.Jar = ses.cookiejar
}
// Head 请求
func (ses *Session) Head(url string) *Workflow {
wf := NewWorkflow(ses, url)
wf.Method = "HEAD"
return wf
}
// Get 请求
func (ses *Session) Get(url string) *Workflow {
wf := NewWorkflow(ses, url)
@ -335,20 +342,6 @@ func (ses *Session) Patch(url string) *Workflow {
return wf
}
// Delete 请求
func (ses *Session) Delete(url string) *Workflow {
wf := NewWorkflow(ses, url)
wf.Method = "DELETE"
return wf
}
// Head 请求
func (ses *Session) Head(url string) *Workflow {
wf := NewWorkflow(ses, url)
wf.Method = "HEAD"
return wf
}
// Options 请求
func (ses *Session) Options(url string) *Workflow {
wf := NewWorkflow(ses, url)
@ -356,6 +349,13 @@ func (ses *Session) Options(url string) *Workflow {
return wf
}
// Delete 请求
func (ses *Session) Delete(url string) *Workflow {
wf := NewWorkflow(ses, url)
wf.Method = "DELETE"
return wf
}
// CloseIdleConnections closes the idle connections that a session client may make use of
// 从levigross/grequests 借鉴
func (ses *Session) CloseIdleConnections() {