Copy http.Header for each Target
Fixes #30 and likely other nasty problems with the internals of the http.Client mutating the shared Header. Thanks @timjnh for reporting.
This commit is contained in:
@@ -58,8 +58,13 @@ func (t Targets) Shuffle(seed int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetHeader sets the passed request header in all Targets
|
// SetHeader sets the passed request header in all Targets
|
||||||
|
// by making a copy for each
|
||||||
func (t Targets) SetHeader(header http.Header) {
|
func (t Targets) SetHeader(header http.Header) {
|
||||||
for _, target := range t {
|
for _, target := range t {
|
||||||
target.Header = header
|
target.Header = make(http.Header, len(header))
|
||||||
|
for k, vs := range header {
|
||||||
|
target.Header[k] = make([]string, len(vs))
|
||||||
|
copy(target.Header[k], vs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,4 +62,9 @@ func TestSetHeader(t *testing.T) {
|
|||||||
t.Errorf("Want: %s, Got: %s", want, got)
|
t.Errorf("Want: %s, Got: %s", want, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Test Header copy
|
||||||
|
targets[0].Header.Set("Authorization", "0")
|
||||||
|
if targets[1].Header.Get("Authorization") == "0" {
|
||||||
|
t.Error("Each Target must have it's own Header")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user