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

Commit 7d4c64b

Browse files
committed
implemented http.RoundTripper
1 parent 76485d3 commit 7d4c64b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

digest_auth_client.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,24 @@ type DigestRequest struct {
1717
Wa *wwwAuthenticate
1818
}
1919

20-
func NewRequest(username string, password string, method string, uri string, body string) DigestRequest {
20+
type DigestTransport struct {
21+
Password string
22+
Username string
23+
}
2124

25+
func NewRequest(username string, password string, method string, uri string, body string) DigestRequest {
2226
dr := DigestRequest{}
2327
dr.UpdateRequest(username, password, method, uri, body)
2428
return dr
2529
}
2630

31+
func NewTransport(username string, password string) DigestTransport {
32+
dt := DigestTransport{}
33+
dt.Password = password
34+
dt.Username = username
35+
return dt
36+
}
37+
2738
func (dr *DigestRequest) UpdateRequest(username string,
2839
password string, method string, uri string, body string) *DigestRequest {
2940

@@ -35,6 +46,23 @@ func (dr *DigestRequest) UpdateRequest(username string,
3546
return dr
3647
}
3748

49+
func (dt *DigestTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
50+
username := dt.Username
51+
password := dt.Password
52+
method := req.Method
53+
uri := req.URL.String()
54+
55+
var body string
56+
if req.Body != nil {
57+
buf := new(bytes.Buffer)
58+
buf.ReadFrom(req.Body)
59+
body = buf.String()
60+
}
61+
62+
dr := NewRequest(username, password, method, uri, body)
63+
return dr.Execute()
64+
}
65+
3866
func (dr *DigestRequest) Execute() (resp *http.Response, err error) {
3967

4068
if dr.Auth == nil {

0 commit comments

Comments
 (0)