优化 mergeMapList

This commit is contained in:
huangsimin 2018-10-24 18:23:04 +08:00
parent 4b77382218
commit 408995f2b4

View File

@ -197,28 +197,20 @@ func (wf *Workflow) SetBodyParams(params ...interface{}) *Workflow {
return wf
}
func mergeMapList(header1, header2 map[string][]string) map[string][]string {
func mergeMapList(headers ...map[string][]string) map[string][]string {
set := make(map[string]map[string]int)
merged := make(map[string][]string)
for key, values := range header1 {
for _, v := range values {
if vs, ok := set[key]; ok {
vs[v] = 1
} else {
set[key] = make(map[string]int)
set[key][v] = 1
}
}
}
for key, values := range header2 {
for _, v := range values {
if vs, ok := set[key]; ok {
vs[v] = 1
} else {
set[key] = make(map[string]int)
set[key][v] = 1
for _, header := range headers {
for key, values := range header {
for _, v := range values {
if vs, ok := set[key]; ok {
vs[v] = 1
} else {
set[key] = make(map[string]int)
set[key][v] = 1
}
}
}
}
@ -239,7 +231,7 @@ func mergeMapList(header1, header2 map[string][]string) map[string][]string {
// setHeaderRequest 设置request的头
func setHeaderRequest(req *http.Request, wf *Workflow) {
req.Header = mergeMapList(req.Header, mergeMapList(wf.session.Header, wf.Header))
req.Header = mergeMapList(req.Header, wf.session.Header, wf.Header)
}
// setHeaderRequest 设置request的临时Cookie, 永久需要在session上设置cookie