Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.

Commit c1e1988

Browse files
committed
minor fixes to improve readability
1 parent 858170f commit c1e1988

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

authorization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (ah *authorization) refreshAuthorization(dr *DigestRequest) (*authorization
6565
if err != nil {
6666
return nil, err
6767
}
68-
ah.Uri = url.RequestURI()
6968

69+
ah.Uri = url.RequestURI()
7070
ah.Response = ah.computeResponse(dr)
7171

7272
return ah, nil

digest_auth_client.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (dr *DigestRequest) Execute() (resp *http.Response, err error) {
7878
if err != nil {
7979
return nil, err
8080
}
81+
defer resp.Body.Close()
8182

8283
if resp.StatusCode == 401 {
8384
return dr.executeNewDigest(resp)
@@ -90,13 +91,13 @@ func (dr *DigestRequest) Execute() (resp *http.Response, err error) {
9091

9192
func (dr *DigestRequest) executeNewDigest(resp *http.Response) (*http.Response, error) {
9293
var (
93-
auth *authorization
94-
err error
95-
wa *wwwAuthenticate
94+
auth *authorization
95+
err error
96+
wa *wwwAuthenticate
97+
waString string
9698
)
9799

98-
waString := resp.Header.Get("WWW-Authenticate")
99-
if waString == "" {
100+
if waString = resp.Header.Get("WWW-Authenticate"); waString == "" {
100101
return nil, fmt.Errorf("failed to get WWW-Authenticate header, please check your server configuration")
101102
}
102103
wa = newWwwAuthenticate(waString)
@@ -107,9 +108,10 @@ func (dr *DigestRequest) executeNewDigest(resp *http.Response) (*http.Response,
107108
}
108109
authString := auth.toString()
109110

110-
if _, err := dr.executeRequest(authString); err != nil {
111+
if resp, err = dr.executeRequest(authString); err != nil {
111112
return nil, err
112113
}
114+
defer resp.Body.Close()
113115

114116
dr.Auth = auth
115117
return resp, nil
@@ -124,8 +126,8 @@ func (dr *DigestRequest) executeExistingDigest() (*http.Response, error) {
124126
if auth, err = dr.Auth.refreshAuthorization(dr); err != nil {
125127
return nil, err
126128
}
127-
dr.Auth = auth
128129

130+
dr.Auth = auth
129131
authString := dr.Auth.toString()
130132
return dr.executeRequest(authString)
131133
}
@@ -141,10 +143,8 @@ func (dr *DigestRequest) executeRequest(authString string) (*http.Response, erro
141143
}
142144

143145
req.Header.Add("Authorization", authString)
144-
145146
client := &http.Client{
146147
Timeout: 30 * time.Second,
147148
}
148-
149149
return client.Do(req)
150150
}

0 commit comments

Comments
 (0)