1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package node
import (
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestParseHTTPHeader(t *testing.T) {
for _, test := range []struct {
desc string
str string
expHdr http.Header
expErr bool
}{
{
desc: "err-empty",
expErr: true,
},
{
desc: "err-no-colon",
str: "Key",
expErr: true,
},
{
desc: "err-only-key",
str: "Key:",
expErr: true,
},
{
desc: "err-no-space",
str: "Key:value",
expErr: true,
},
{
desc: "valid",
str: "Key: value",
expHdr: http.Header{"Key": []string{"value"}},
},
{
desc: "valid-small",
str: "key: value",
expHdr: http.Header{"Key": []string{"value"}},
},
{
desc: "valid-spaces-colons",
str: "X-Key: a long value with spaces: and: colons",
expHdr: http.Header{"X-Key": []string{"a long value with spaces: and: colons"}},
},
} {
t.Run(test.desc, func(t *testing.T) {
h, err := parseHTTPHeader(test.str)
if test.expErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, test.expHdr, h)
}
})
}
}