Skip to content

Commit

Permalink
Refactored validation/setting of extraHttpHeaders
Browse files Browse the repository at this point in the history
Signed-off-by: Graeme Christie <[email protected]>
  • Loading branch information
graemechristie committed Nov 1, 2023
1 parent 8a31ee7 commit be913f2
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ func main() {
log.Fatalf("Invalid scheme for upstream URL %q, only 'http' and 'https' are supported", upstream)
}

for _, headerArg := range extraHttpHeaders {
header, val, found := strings.Cut(headerArg, ":")
if !found || len(strings.TrimSpace(header)) == 0 || len(strings.TrimSpace(val)) == 0 {
log.Fatalf("extra-http-header %s is not in the format 'key:value'", headerArg)
}
}

reg := prometheus.NewRegistry()
reg.MustRegister(
collectors.NewGoCollector(),
Expand All @@ -137,8 +130,12 @@ func main() {
opts = append(opts, injectproxy.WithErrorOnReplace())
}

if len(extraHttpHeaders) > 0 {
opts = append(opts, injectproxy.WithExtraHttpHeaders(extraHttpHeaders))
for _, headerArg := range extraHttpHeaders {
header, val, found := strings.Cut(headerArg, ":")
if !found || len(strings.TrimSpace(header)) == 0 || len(strings.TrimSpace(val)) == 0 {
log.Fatalf("extra-http-header %s is not in the format 'key:value'", headerArg)
}
opts = append(opts, injectproxy.WithExtraHttpHeader(header, val))
}

if len(rewriteHostHeader) > 0 {
Expand Down

0 comments on commit be913f2

Please sign in to comment.