From ff7f7379045793c29350fc96d10d0250d64ad57f Mon Sep 17 00:00:00 2001 From: vitalii Date: Sat, 5 Oct 2019 22:13:01 +0300 Subject: [PATCH] fix(requests.go): allow www-authenticate to be case-insensitive. close #32 --- requests.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/requests.go b/requests.go index 511e890..3753a75 100644 --- a/requests.go +++ b/requests.go @@ -43,10 +43,15 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R } if rs.StatusCode == 401 && c.auth.Type() == "NoAuth" { - if strings.Index(rs.Header.Get("Www-Authenticate"), "Digest") > -1 { + + wwwAuthenticateHeader := strings.ToLower(rs.Header.Get("Www-Authenticate")) + + if strings.Index(wwwAuthenticateHeader, "digest") > -1 { c.auth = &DigestAuth{c.auth.User(), c.auth.Pass(), digestParts(rs)} - } else if strings.Index(rs.Header.Get("Www-Authenticate"), "Basic") > -1 { + + } else if strings.Index(wwwAuthenticateHeader, "basic") > -1 { c.auth = &BasicAuth{c.auth.User(), c.auth.Pass()} + } else { return rs, newPathError("Authorize", c.root, rs.StatusCode) }