@@ -2,6 +2,7 @@ package digest_auth_client
2
2
3
3
import (
4
4
"bytes"
5
+ "crypto/tls"
5
6
"fmt"
6
7
"net/http"
7
8
"time"
@@ -11,10 +12,12 @@ type DigestRequest struct {
11
12
Body string
12
13
Method string
13
14
Password string
14
- Uri string
15
+ URI string
15
16
Username string
17
+ Header http.Header
16
18
Auth * authorization
17
19
Wa * wwwAuthenticate
20
+ CertVal bool
18
21
}
19
22
20
23
type DigestTransport struct {
@@ -26,6 +29,7 @@ type DigestTransport struct {
26
29
func NewRequest (username , password , method , uri , body string ) DigestRequest {
27
30
dr := DigestRequest {}
28
31
dr .UpdateRequest (username , password , method , uri , body )
32
+ dr .CertVal = true
29
33
return dr
30
34
}
31
35
@@ -43,8 +47,9 @@ func (dr *DigestRequest) UpdateRequest(username, password, method, uri, body str
43
47
dr .Body = body
44
48
dr .Method = method
45
49
dr .Password = password
46
- dr .Uri = uri
50
+ dr .URI = uri
47
51
dr .Username = username
52
+ dr .Header = make (map [string ][]string )
48
53
return dr
49
54
}
50
55
@@ -74,13 +79,22 @@ func (dr *DigestRequest) Execute() (resp *http.Response, err error) {
74
79
}
75
80
76
81
var req * http.Request
77
- if req , err = http .NewRequest (dr .Method , dr .Uri , bytes .NewReader ([]byte (dr .Body ))); err != nil {
82
+ if req , err = http .NewRequest (dr .Method , dr .URI , bytes .NewReader ([]byte (dr .Body ))); err != nil {
78
83
return nil , err
79
84
}
85
+ req .Header = dr .Header
80
86
81
87
client := & http.Client {
82
88
Timeout : 30 * time .Second ,
83
89
}
90
+
91
+ if ! dr .CertVal {
92
+ tr := & http.Transport {
93
+ TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
94
+ }
95
+ client .Transport = tr
96
+ }
97
+
84
98
if resp , err = client .Do (req ); err != nil {
85
99
return nil , err
86
100
}
@@ -135,15 +149,22 @@ func (dr *DigestRequest) executeExistingDigest() (resp *http.Response, err error
135
149
func (dr * DigestRequest ) executeRequest (authString string ) (resp * http.Response , err error ) {
136
150
var req * http.Request
137
151
138
- if req , err = http .NewRequest (dr .Method , dr .Uri , bytes .NewReader ([]byte (dr .Body ))); err != nil {
152
+ if req , err = http .NewRequest (dr .Method , dr .URI , bytes .NewReader ([]byte (dr .Body ))); err != nil {
139
153
return nil , err
140
154
}
141
-
155
+ req . Header = dr . Header
142
156
req .Header .Add ("Authorization" , authString )
143
157
144
158
client := & http.Client {
145
159
Timeout : 30 * time .Second ,
146
160
}
147
161
162
+ if ! dr .CertVal {
163
+ tr := & http.Transport {
164
+ TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
165
+ }
166
+ client .Transport = tr
167
+ }
168
+
148
169
return client .Do (req )
149
170
}
0 commit comments