From a6217886dc6ec3c1dfc9a991457ce05407e54fa4 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Wed, 21 Nov 2018 17:43:22 +0800 Subject: [PATCH] fix SetHeader Replace src header(copy all header in a new http.Header) --- workflow.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/workflow.go b/workflow.go index 2029893..a5da8ad 100644 --- a/workflow.go +++ b/workflow.go @@ -41,9 +41,16 @@ func (wf *Workflow) AddHeader(key, value string) *Workflow { return wf } -// SetHeader 设置头信息 这样构造 []string{value} Get方法从Header参数上获取 -func (wf *Workflow) SetHeader(key, value string) *Workflow { - wf.Header.Set(key, value) +// SetHeader 设置完全替换原有Header +func (wf *Workflow) SetHeader(header http.Header) *Workflow { + wf.Header = make(http.Header) + for k, HValues := range header { + var newHValues []string + for _, value := range HValues { + newHValues = append(newHValues, value) + } + wf.Header[k] = newHValues + } return wf } @@ -69,6 +76,14 @@ func (wf *Workflow) AddCookie(c *http.Cookie) *Workflow { return wf } +// AddCookies 添加[]*http.Cookie +func (wf *Workflow) AddCookies(cookies []*http.Cookie) *Workflow { + for _, c := range cookies { + wf.AddCookie(c) + } + return wf +} + // AddKVCookie 添加 以 key value 的 Cookie func (wf *Workflow) AddKVCookie(name, value string) *Workflow { wf.Cookies[name] = &http.Cookie{Name: name, Value: value}