@@ -17,13 +17,24 @@ type DigestRequest struct {
17
17
Wa * wwwAuthenticate
18
18
}
19
19
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
+ }
21
24
25
+ func NewRequest (username string , password string , method string , uri string , body string ) DigestRequest {
22
26
dr := DigestRequest {}
23
27
dr .UpdateRequest (username , password , method , uri , body )
24
28
return dr
25
29
}
26
30
31
+ func NewTransport (username string , password string ) DigestTransport {
32
+ dt := DigestTransport {}
33
+ dt .Password = password
34
+ dt .Username = username
35
+ return dt
36
+ }
37
+
27
38
func (dr * DigestRequest ) UpdateRequest (username string ,
28
39
password string , method string , uri string , body string ) * DigestRequest {
29
40
@@ -35,6 +46,23 @@ func (dr *DigestRequest) UpdateRequest(username string,
35
46
return dr
36
47
}
37
48
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
+
38
66
func (dr * DigestRequest ) Execute () (resp * http.Response , err error ) {
39
67
40
68
if dr .Auth == nil {
0 commit comments