requests: nil pointer dereference panic was fixed [#25]

http.Do() method will return non-nil [error] in following cases:
1. Request is nil
2. Response missing Location header
3. Client failed to parse Location header
4. Method "request.GetBody()" returns error
5. Http.Client.Send() returns error
5. Client timeout was exceeded

Signed-off-by: Christoph Polcin <labs@polcin.de>
This commit is contained in:
vitalii 2018-09-04 23:48:06 +03:00 committed by Christoph Polcin
parent 3cd755d6c4
commit a68e21e92b

View File

@ -38,6 +38,9 @@ func (c *Client) req(method, path string, body io.Reader, intercept func(*http.R
} }
rs, err := c.c.Do(r) rs, err := c.c.Do(r)
if err != nil {
return nil, err
}
if rs.StatusCode == 401 && c.auth.Type() == "NoAuth" { if rs.StatusCode == 401 && c.auth.Type() == "NoAuth" {
if strings.Index(rs.Header.Get("Www-Authenticate"), "Digest") > -1 { if strings.Index(rs.Header.Get("Www-Authenticate"), "Digest") > -1 {