test all success!
This commit is contained in:
parent
02bc589ba3
commit
d382505453
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
*.pyc
|
||||
*.vscode
|
||||
|
|
29
session.go
29
session.go
|
@ -18,6 +18,8 @@ import (
|
|||
type Body struct {
|
||||
// Query map[string][]string
|
||||
ioBody interface{}
|
||||
// prefix ContentType 前缀
|
||||
prefix string
|
||||
// Files []UploadFile
|
||||
contentTypes map[string]int
|
||||
}
|
||||
|
@ -41,19 +43,36 @@ func (body *Body) IOBody() interface{} {
|
|||
|
||||
// ContentType 获取ContentType
|
||||
func (body *Body) ContentType() string {
|
||||
content := ""
|
||||
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
|
||||
}
|
||||
|
||||
// AddContentType 添加 Add Type类型
|
||||
func (body *Body) AddContentType(ct string) {
|
||||
for _, v := range strings.Split(ct, ";") {
|
||||
v = strings.Trim(v, " ")
|
||||
if v != "" {
|
||||
body.contentTypes[v] = 1
|
||||
if body.prefix != v {
|
||||
body.contentTypes[v] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +89,8 @@ type IBody interface {
|
|||
ContentType() string
|
||||
// AppendContent
|
||||
AddContentType(ct string)
|
||||
// AddPrefix 添加 Prefix
|
||||
AddPrefix(ct string)
|
||||
}
|
||||
|
||||
// BasicAuth 帐号认真结构
|
||||
|
@ -105,10 +126,10 @@ const (
|
|||
TypeURLENCODED = "application/x-www-form-urlencoded"
|
||||
// TypeForm PostForm类型
|
||||
TypeForm = TypeURLENCODED
|
||||
// TypeContentEmpty 没有Form的类型 Content
|
||||
TypeContentEmpty = "ContentEmpty"
|
||||
// TypeFormData 类型
|
||||
TypeFormData = "multipart/form-data"
|
||||
// TypeMixed Mixed类型
|
||||
TypeMixed = "multipart/mixed"
|
||||
|
||||
// HeaderKeyHost Host
|
||||
HeaderKeyHost = "Host"
|
||||
|
|
10
workflow.go
10
workflow.go
|
@ -1,6 +1,7 @@
|
|||
package requests
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
|
@ -175,23 +176,22 @@ func (wf *Workflow) SetURLRawPath(path string) *Workflow {
|
|||
|
||||
// SetBody 参数设置
|
||||
func (wf *Workflow) SetBody(params ...interface{}) *Workflow {
|
||||
if params != nil {
|
||||
|
||||
if params != nil {
|
||||
plen := len(params)
|
||||
defaultContentType := TypeURLENCODED
|
||||
|
||||
if plen >= 2 {
|
||||
t := params[plen-1]
|
||||
defaultContentType = t.(string)
|
||||
wf.Body.AddContentType(defaultContentType)
|
||||
wf.Body.AddPrefix(defaultContentType)
|
||||
} else {
|
||||
wf.Body.AddContentType(defaultContentType)
|
||||
wf.Body.AddPrefix(defaultContentType)
|
||||
}
|
||||
|
||||
if defaultContentType == TypeFormData {
|
||||
createMultipart(wf.Body, params)
|
||||
} else {
|
||||
|
||||
var values url.Values
|
||||
switch param := params[0].(type) {
|
||||
case map[string]string:
|
||||
|
@ -211,7 +211,7 @@ func (wf *Workflow) SetBody(params ...interface{}) *Workflow {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
log.Println(wf.Body.ContentType())
|
||||
return wf
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user