Skip to content

Commit 58dbc95

Browse files
committed
http/httpguts: add test and benchmark for ValidHeaderFieldName
1 parent 581669b commit 58dbc95

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

http/httpguts/httplex_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,44 @@ func TestHeaderValuesContainsToken(t *testing.T) {
109109
}
110110
}
111111

112+
func TestValidHeaderFieldName(t *testing.T) {
113+
tests := []struct {
114+
in string
115+
want bool
116+
}{
117+
{"", false},
118+
{"Accept Charset", false},
119+
{"Accept-Charset", true},
120+
{"AccepT-EncodinG", true},
121+
{"CONNECTION", true},
122+
{"résumé", false},
123+
}
124+
for _, tt := range tests {
125+
got := ValidHeaderFieldName(tt.in)
126+
if tt.want != got {
127+
t.Errorf("ValidHeaderFieldName(%q) = %t; want %t", tt.in, got, tt.want)
128+
}
129+
}
130+
}
131+
132+
func BenchmarkValidHeaderFieldName(b *testing.B) {
133+
names := []string{
134+
"",
135+
"Accept Charset",
136+
"Accept-Charset",
137+
"AccepT-EncodinG",
138+
"CONNECTION",
139+
"résumé",
140+
}
141+
b.ReportAllocs()
142+
b.ResetTimer()
143+
for i := 0; i < b.N; i++ {
144+
for _, name := range names {
145+
ValidHeaderFieldName(name)
146+
}
147+
}
148+
}
149+
112150
func TestPunycodeHostPort(t *testing.T) {
113151
tests := []struct {
114152
in, want string

0 commit comments

Comments
 (0)