Skip to content

Commit 569e99a

Browse files
authored
Merge pull request #177 from fastly/dgryski/header-apply
fsthttp: override old values in header.Apply()
2 parents 6f19609 + 456987a commit 569e99a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

fsthttp/headers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (h Header) Reset(hs Header) {
8585
// values from hs totally overwrite existing values in h.
8686
func (h Header) Apply(hs Header) {
8787
for _, key := range hs.Keys() {
88+
h.Del(key)
8889
for _, value := range hs.Values(key) {
8990
h.Add(key, value)
9091
}

fsthttp/headers_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package fsthttp
44

55
import (
6+
"reflect"
67
"testing"
78
)
89

@@ -16,3 +17,19 @@ func TestHeaderBasics(t *testing.T) {
1617
t.Errorf("Host: want %q, have %q", want, have)
1718
}
1819
}
20+
21+
func TestHeaderApply(t *testing.T) {
22+
t.Parallel()
23+
24+
h := NewHeader()
25+
h.Add("Host", "zombo.com")
26+
27+
h2 := NewHeader()
28+
h2.Add("Host", "zombo2.com")
29+
30+
h.Apply(h2)
31+
32+
if got, want := h.Values("Host"), []string{"zombo2.com"}; !reflect.DeepEqual(got, want) {
33+
t.Errorf("Host: got %q, want %q", got, want)
34+
}
35+
}

0 commit comments

Comments
 (0)