change prefix; prefix not a array;

This commit is contained in:
huangsimin 2018-11-20 15:55:13 +08:00
parent 23a369677f
commit 137121ee59
2 changed files with 7 additions and 19 deletions

View File

@ -43,26 +43,16 @@ func (body *Body) IOBody() interface{} {
// ContentType 获取ContentType
func (body *Body) ContentType() string {
content := body.prefix + ";"
content := body.prefix
for kvalue := range body.contentTypes {
content += kvalue + ";"
}
return strings.TrimRight(content, ";")
}
// AddPrefix AddPrefix 和 AddContentType的顺序会影响到ContentType()的返回结果
func (body *Body) AddPrefix(ct string) {
content := body.prefix
for _, v := range strings.Split(ct, ";") {
v = strings.Trim(v, " ")
if v != "" {
if body.prefix != v {
content += v + ";"
}
}
}
content = strings.TrimRight(content, ";")
body.prefix = content
// SetPrefix SetPrefix 和 AddContentType的顺序会影响到ContentType()的返回结果
func (body *Body) SetPrefix(ct string) {
body.prefix = strings.TrimRight(ct, ";") + ";"
}
// AddContentType 添加 Add Type类型
@ -90,7 +80,7 @@ type IBody interface {
// AppendContent
AddContentType(ct string)
// AddPrefix 添加 Prefix
AddPrefix(ct string)
SetPrefix(ct string)
}
// BasicAuth 帐号认真结构

View File

@ -1,7 +1,6 @@
package requests
import (
"log"
"net/http"
"net/url"
"regexp"
@ -184,9 +183,9 @@ func (wf *Workflow) SetBody(params ...interface{}) *Workflow {
if plen >= 2 {
t := params[plen-1]
defaultContentType = t.(string)
wf.Body.AddPrefix(defaultContentType)
wf.Body.SetPrefix(defaultContentType)
} else {
wf.Body.AddPrefix(defaultContentType)
wf.Body.SetPrefix(defaultContentType)
}
if defaultContentType == TypeFormData {
@ -211,7 +210,6 @@ func (wf *Workflow) SetBody(params ...interface{}) *Workflow {
}
}
log.Println(wf.Body.ContentType())
return wf
}