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

Commit dd84304

Browse files
committed
Add support for setting custom timeout
Users can now set DigestTransport.Timeout and DigestRequest.Timeout to control the underlying http.Client.Timeout. Closes #14
1 parent 9da83de commit dd84304

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

digest_auth_client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@ type DigestRequest struct {
1818
Auth *authorization
1919
Wa *wwwAuthenticate
2020
CertVal bool
21+
Timeout time.Duration
2122
}
2223

2324
type DigestTransport struct {
2425
Password string
2526
Username string
27+
Timeout time.Duration
2628
}
2729

2830
// NewRequest creates a new DigestRequest object
2931
func NewRequest(username, password, method, uri, body string) DigestRequest {
3032
dr := DigestRequest{}
3133
dr.UpdateRequest(username, password, method, uri, body)
3234
dr.CertVal = true
35+
dr.Timeout = 30 * time.Second
3336
return dr
3437
}
3538

@@ -38,6 +41,7 @@ func NewTransport(username, password string) DigestTransport {
3841
dt := DigestTransport{}
3942
dt.Password = password
4043
dt.Username = username
44+
dt.Timeout = 30 * time.Second
4145
return dt
4246
}
4347

@@ -68,6 +72,7 @@ func (dt *DigestTransport) RoundTrip(req *http.Request) (resp *http.Response, er
6872
}
6973

7074
dr := NewRequest(username, password, method, uri, body)
75+
dr.Timeout = dt.Timeout
7176
return dr.Execute()
7277
}
7378

@@ -85,7 +90,7 @@ func (dr *DigestRequest) Execute() (resp *http.Response, err error) {
8590
req.Header = dr.Header
8691

8792
client := &http.Client{
88-
Timeout: 30 * time.Second,
93+
Timeout: dr.Timeout,
8994
}
9095

9196
if !dr.CertVal {
@@ -156,7 +161,7 @@ func (dr *DigestRequest) executeRequest(authString string) (resp *http.Response,
156161
req.Header.Add("Authorization", authString)
157162

158163
client := &http.Client{
159-
Timeout: 30 * time.Second,
164+
Timeout: dr.Timeout,
160165
}
161166

162167
if !dr.CertVal {

0 commit comments

Comments
 (0)