EmailConfig: Use CanonicalMIMEHeaderKey instead of TitleCasing for headers (#3080)

* EmailConfig: Use CanonicalMIMEHeaderKey instead of TitleCasing for headers

Fixes #3064.

Signed-off-by: Joe Blubaugh <joe.blubaugh@grafana.com>

* Remove an unused field.

Signed-off-by: Joe Blubaugh <joe.blubaugh@grafana.com>

Signed-off-by: Joe Blubaugh <joe.blubaugh@grafana.com>
This commit is contained in:
Joe Blubaugh 2022-09-22 20:41:25 +08:00 committed by GitHub
parent efc956c7f7
commit dc0913b252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 5 deletions

View File

@ -15,6 +15,7 @@ package config
import (
"fmt"
"net/textproto"
"regexp"
"strings"
"time"
@ -22,8 +23,6 @@ import (
"github.com/pkg/errors"
commoncfg "github.com/prometheus/common/config"
"github.com/prometheus/common/sigv4"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
var (
@ -147,8 +146,6 @@ var (
Message: `{{ template "telegram.default.message" . }}`,
ParseMode: "HTML",
}
normalizeTitle = cases.Title(language.AmericanEnglish)
)
// NotifierConfig contains base options common across all notifier configurations.
@ -194,7 +191,7 @@ func (c *EmailConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Header names are case-insensitive, check for collisions.
normalizedHeaders := map[string]string{}
for h, v := range c.Headers {
normalized := normalizeTitle.String(h)
normalized := textproto.CanonicalMIMEHeaderKey(h)
if _, ok := normalizedHeaders[normalized]; ok {
return fmt.Errorf("duplicate header %q in email config", normalized)
}