@@ -78,6 +78,7 @@ func (dr *DigestRequest) Execute() (resp *http.Response, err error) {
78
78
if err != nil {
79
79
return nil , err
80
80
}
81
+ defer resp .Body .Close ()
81
82
82
83
if resp .StatusCode == 401 {
83
84
return dr .executeNewDigest (resp )
@@ -90,13 +91,13 @@ func (dr *DigestRequest) Execute() (resp *http.Response, err error) {
90
91
91
92
func (dr * DigestRequest ) executeNewDigest (resp * http.Response ) (* http.Response , error ) {
92
93
var (
93
- auth * authorization
94
- err error
95
- wa * wwwAuthenticate
94
+ auth * authorization
95
+ err error
96
+ wa * wwwAuthenticate
97
+ waString string
96
98
)
97
99
98
- waString := resp .Header .Get ("WWW-Authenticate" )
99
- if waString == "" {
100
+ if waString = resp .Header .Get ("WWW-Authenticate" ); waString == "" {
100
101
return nil , fmt .Errorf ("failed to get WWW-Authenticate header, please check your server configuration" )
101
102
}
102
103
wa = newWwwAuthenticate (waString )
@@ -107,9 +108,10 @@ func (dr *DigestRequest) executeNewDigest(resp *http.Response) (*http.Response,
107
108
}
108
109
authString := auth .toString ()
109
110
110
- if _ , err : = dr .executeRequest (authString ); err != nil {
111
+ if resp , err = dr .executeRequest (authString ); err != nil {
111
112
return nil , err
112
113
}
114
+ defer resp .Body .Close ()
113
115
114
116
dr .Auth = auth
115
117
return resp , nil
@@ -124,8 +126,8 @@ func (dr *DigestRequest) executeExistingDigest() (*http.Response, error) {
124
126
if auth , err = dr .Auth .refreshAuthorization (dr ); err != nil {
125
127
return nil , err
126
128
}
127
- dr .Auth = auth
128
129
130
+ dr .Auth = auth
129
131
authString := dr .Auth .toString ()
130
132
return dr .executeRequest (authString )
131
133
}
@@ -141,10 +143,8 @@ func (dr *DigestRequest) executeRequest(authString string) (*http.Response, erro
141
143
}
142
144
143
145
req .Header .Add ("Authorization" , authString )
144
-
145
146
client := & http.Client {
146
147
Timeout : 30 * time .Second ,
147
148
}
148
-
149
149
return client .Do (req )
150
150
}
0 commit comments