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

Commit ea9536d

Browse files
authored
Merge branch 'master' into allow-setting-custom-http-client
2 parents 9ec501a + a94f932 commit ea9536d

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

authorization.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,48 +130,48 @@ func (ah *authorization) toString() string {
130130

131131
buffer.WriteString("Digest ")
132132

133-
if ah.Algorithm != "" {
134-
buffer.WriteString(fmt.Sprintf("algorithm=%s, ", ah.Algorithm))
133+
if ah.Username != "" {
134+
buffer.WriteString(fmt.Sprintf("username=\"%s\", ", ah.Username))
135135
}
136136

137-
if ah.Cnonce != "" {
138-
buffer.WriteString(fmt.Sprintf("cnonce=\"%s\", ", ah.Cnonce))
137+
if ah.Realm != "" {
138+
buffer.WriteString(fmt.Sprintf("realm=\"%s\", ", ah.Realm))
139139
}
140140

141-
if ah.Nc != 0 {
142-
buffer.WriteString(fmt.Sprintf("nc=%08x, ", ah.Nc))
141+
if ah.Nonce != "" {
142+
buffer.WriteString(fmt.Sprintf("nonce=\"%s\", ", ah.Nonce))
143143
}
144144

145-
if ah.Opaque != "" {
146-
buffer.WriteString(fmt.Sprintf("opaque=\"%s\", ", ah.Opaque))
145+
if ah.URI != "" {
146+
buffer.WriteString(fmt.Sprintf("uri=\"%s\", ", ah.URI))
147147
}
148148

149-
if ah.Nonce != "" {
150-
buffer.WriteString(fmt.Sprintf("nonce=\"%s\", ", ah.Nonce))
149+
if ah.Response != "" {
150+
buffer.WriteString(fmt.Sprintf("response=\"%s\", ", ah.Response))
151151
}
152152

153-
if ah.Qop != "" {
154-
buffer.WriteString(fmt.Sprintf("qop=%s, ", ah.Qop))
153+
if ah.Algorithm != "" {
154+
buffer.WriteString(fmt.Sprintf("algorithm=%s, ", ah.Algorithm))
155155
}
156156

157-
if ah.Realm != "" {
158-
buffer.WriteString(fmt.Sprintf("realm=\"%s\", ", ah.Realm))
157+
if ah.Cnonce != "" {
158+
buffer.WriteString(fmt.Sprintf("cnonce=\"%s\", ", ah.Cnonce))
159159
}
160160

161-
if ah.Response != "" {
162-
buffer.WriteString(fmt.Sprintf("response=\"%s\", ", ah.Response))
161+
if ah.Opaque != "" {
162+
buffer.WriteString(fmt.Sprintf("opaque=\"%s\", ", ah.Opaque))
163163
}
164164

165-
if ah.URI != "" {
166-
buffer.WriteString(fmt.Sprintf("uri=\"%s\", ", ah.URI))
165+
if ah.Qop != "" {
166+
buffer.WriteString(fmt.Sprintf("qop=%s, ", ah.Qop))
167167
}
168168

169-
if ah.Userhash {
170-
buffer.WriteString("userhash=true, ")
169+
if ah.Nc != 0 {
170+
buffer.WriteString(fmt.Sprintf("nc=%08x, ", ah.Nc))
171171
}
172172

173-
if ah.Username != "" {
174-
buffer.WriteString(fmt.Sprintf("username=\"%s\", ", ah.Username))
173+
if ah.Userhash {
174+
buffer.WriteString("userhash=true, ")
175175
}
176176

177177
s := buffer.String()

digest_auth_client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ type DigestRequest struct {
2424
type DigestTransport struct {
2525
Password string
2626
Username string
27+
Timeout time.Duration
2728
}
2829

2930
// NewRequest creates a new DigestRequest object
3031
func NewRequest(username, password, method, uri, body string) DigestRequest {
3132
dr := DigestRequest{}
3233
dr.UpdateRequest(username, password, method, uri, body)
3334
dr.CertVal = true
35+
dr.Timeout = 30 * time.Second
3436
return dr
3537
}
3638

@@ -39,6 +41,7 @@ func NewTransport(username, password string) DigestTransport {
3941
dt := DigestTransport{}
4042
dt.Password = password
4143
dt.Username = username
44+
dt.Timeout = 30 * time.Second
4245
return dt
4346
}
4447

@@ -86,6 +89,7 @@ func (dt *DigestTransport) RoundTrip(req *http.Request) (resp *http.Response, er
8689
}
8790

8891
dr := NewRequest(username, password, method, uri, body)
92+
dr.Timeout = dt.Timeout
8993
return dr.Execute()
9094
}
9195

www_authenticate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func newWwwAuthenticate(s string) *wwwAuthenticate {
2121

2222
var wa = wwwAuthenticate{}
2323

24-
algorithmRegex := regexp.MustCompile(`algorithm=([^ ,]+)`)
24+
algorithmRegex := regexp.MustCompile(`algorithm="([^ ,]+)"`)
2525
algorithmMatch := algorithmRegex.FindStringSubmatch(s)
2626
if algorithmMatch != nil {
2727
wa.Algorithm = algorithmMatch[1]

0 commit comments

Comments
 (0)