From: nikosmonaut Date: Thu, 12 Dec 2019 15:33:37 +0000 (+0100) Subject: Handle empty User-Agent param X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=36b2245fac212d87d286b99d5a62f0d824c341f9;p=blackbox_exporter.git Handle empty User-Agent param Signed-off-by: nikosmonaut --- diff --git a/prober/http.go b/prober/http.go index 8df0d22..555a10a 100644 --- a/prober/http.go +++ b/prober/http.go @@ -227,7 +227,7 @@ func (t *transport) GotFirstResponseByte() { t.current.responseStart = time.Now() } -var userAgentDefaultHeader = fmt.Sprintf("BlackBox Exporter/%s", version.Version) +var userAgentDefaultHeader = fmt.Sprintf("Blackbox Exporter/%s", version.Version) func ProbeHTTP(ctx context.Context, target string, module config.Module, registry *prometheus.Registry, logger log.Logger) (success bool) { var redirects int @@ -406,7 +406,8 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr request.Header.Set(key, value) } - if request.Header.Get("User-Agent") == "" { + _, hasUserAgent := request.Header["User-Agent"] + if !hasUserAgent { request.Header.Set("User-Agent", userAgentDefaultHeader) }