From 3a62319a693741bf67afe15bc2a11af7dbcd435f Mon Sep 17 00:00:00 2001 From: coverste Date: Tue, 30 Jul 2019 14:55:08 -0700 Subject: [PATCH] code review comments --- web_requester.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/web_requester.go b/web_requester.go index 7f5d806..f4d6dab 100644 --- a/web_requester.go +++ b/web_requester.go @@ -162,17 +162,17 @@ func (w *webRequester) Request() error { var hosts []string - // headers are case-insensitive - for k, v := range w.headers { - if strings.ToLower(k) == "host" { - hosts = append(hosts, v...) + //case insensitive + if host, ok := w.headers["host"]; ok { + if len(hosts) != 1 { + return errors.New("multiple host headers are not allowed") } - } - if len(hosts) > 1 { - return errors.New("multiple host headers are not allowed") - } - if len(hosts) > 0 { - req.Host = hosts[0] + req.Host = host[0] + } else if host, ok = w.headers["Host"]; ok { + if len(hosts) != 1 { + return errors.New("multiple host headers are not allowed") + } + req.Host = host[0] } resp, err := httpClient.Do(req)