diff --git a/workflow.go b/workflow.go index d11c47a..cb45fd8 100644 --- a/workflow.go +++ b/workflow.go @@ -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