Skip to content

Commit

Permalink
EmailConfig: Use CanonicalMIMEHeaderKey instead of TitleCasing for he…
Browse files Browse the repository at this point in the history
…aders (prometheus#3080)

* EmailConfig: Use CanonicalMIMEHeaderKey instead of TitleCasing for headers

Fixes prometheus#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>
Signed-off-by: Yijie Qin <qinyijie@amazon.com>
  • Loading branch information
joeblubaugh authored and qinxx108 committed Dec 13, 2022
1 parent 28ba3b5 commit a0d8d76
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions config/notifiers.go
Expand Up @@ -15,15 +15,14 @@ package config

import (
"fmt"
"net/textproto"
"regexp"
"strings"
"time"

"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 (
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a0d8d76

Please sign in to comment.