Implement Targets#SetHeader

This commit is contained in:
Tomás Senart
2013-09-20 18:17:29 +02:00
parent 1fbb0c5339
commit e75a244b61
2 changed files with 18 additions and 0 deletions

View File

@@ -56,3 +56,10 @@ func (t Targets) Shuffle(seed int64) {
t[i], t[rnd] = t[rnd], t[i]
}
}
// SetHeader sets the passed request header in all Targets
func (t Targets) SetHeader(header http.Header) {
for _, target := range t {
target.Header = header
}
}

View File

@@ -52,3 +52,14 @@ func TestShuffle(t *testing.T) {
}
t.Fatal("Targets were not shuffled correctly")
}
func TestSetHeader(t *testing.T) {
targets, _ := NewTargets([]string{"GET http://lolcathost:9999/", "HEAD http://lolcathost:9999/"})
want := "lolcathost.com"
targets.SetHeader(http.Header{"Host": []string{want}})
for _, target := range targets {
if got := target.Header.Get("Host"); got != want {
t.Errorf("Want: %s, Got: %s", want, got)
}
}
}