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

Commit 5ccd624

Browse files
committed
Adding headers to request and fixing case on URI name
1 parent 3667601 commit 5ccd624

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

authorization.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type authorization struct {
2323
Qop string // unquoted
2424
Realm string // quoted
2525
Response string // quoted
26-
Uri string // quoted
26+
URI string // quoted
2727
Userhash bool // quoted
2828
Username string // quoted
2929
Username_ string // quoted
@@ -40,7 +40,7 @@ func newAuthorization(dr *DigestRequest) (*authorization, error) {
4040
Qop: "",
4141
Realm: dr.Wa.Realm,
4242
Response: "",
43-
Uri: "",
43+
URI: "",
4444
Userhash: dr.Wa.Userhash,
4545
Username: "",
4646
Username_: "", // TODO
@@ -61,12 +61,12 @@ func (ah *authorization) refreshAuthorization(dr *DigestRequest) (*authorization
6161

6262
ah.Cnonce = ah.hash(fmt.Sprintf("%d:%s:my_value", time.Now().UnixNano(), dr.Username))
6363

64-
url, err := url.Parse(dr.Uri)
64+
url, err := url.Parse(dr.URI)
6565
if err != nil {
6666
return nil, err
6767
}
6868

69-
ah.Uri = url.RequestURI()
69+
ah.URI = url.RequestURI()
7070
ah.Response = ah.computeResponse(dr)
7171

7272
return ah, nil
@@ -98,12 +98,12 @@ func (ah *authorization) computeA2(dr *DigestRequest) string {
9898

9999
if matched, _ := regexp.MatchString("auth-int", dr.Wa.Qop); matched {
100100
ah.Qop = "auth-int"
101-
return fmt.Sprintf("%s:%s:%s", dr.Method, ah.Uri, ah.hash(dr.Body))
101+
return fmt.Sprintf("%s:%s:%s", dr.Method, ah.URI, ah.hash(dr.Body))
102102
}
103103

104104
if dr.Wa.Qop == "auth" || dr.Wa.Qop == "" {
105105
ah.Qop = "auth"
106-
return fmt.Sprintf("%s:%s", dr.Method, ah.Uri)
106+
return fmt.Sprintf("%s:%s", dr.Method, ah.URI)
107107
}
108108

109109
return ""
@@ -162,8 +162,8 @@ func (ah *authorization) toString() string {
162162
buffer.WriteString(fmt.Sprintf("response=\"%s\", ", ah.Response))
163163
}
164164

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

169169
if ah.Userhash {

digest_auth_client.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ type DigestRequest struct {
1111
Body string
1212
Method string
1313
Password string
14-
Uri string
14+
URI string
1515
Username string
16+
Header http.Header
1617
Auth *authorization
1718
Wa *wwwAuthenticate
1819
}
@@ -43,7 +44,7 @@ func (dr *DigestRequest) UpdateRequest(username, password, method, uri, body str
4344
dr.Body = body
4445
dr.Method = method
4546
dr.Password = password
46-
dr.Uri = uri
47+
dr.URI = uri
4748
dr.Username = username
4849
return dr
4950
}
@@ -74,9 +75,10 @@ func (dr *DigestRequest) Execute() (resp *http.Response, err error) {
7475
}
7576

7677
var req *http.Request
77-
if req, err = http.NewRequest(dr.Method, dr.Uri, bytes.NewReader([]byte(dr.Body))); err != nil {
78+
if req, err = http.NewRequest(dr.Method, dr.URI, bytes.NewReader([]byte(dr.Body))); err != nil {
7879
return nil, err
7980
}
81+
req.Header = dr.Header
8082

8183
client := &http.Client{
8284
Timeout: 30 * time.Second,
@@ -135,10 +137,10 @@ func (dr *DigestRequest) executeExistingDigest() (resp *http.Response, err error
135137
func (dr *DigestRequest) executeRequest(authString string) (resp *http.Response, err error) {
136138
var req *http.Request
137139

138-
if req, err = http.NewRequest(dr.Method, dr.Uri, bytes.NewReader([]byte(dr.Body))); err != nil {
140+
if req, err = http.NewRequest(dr.Method, dr.URI, bytes.NewReader([]byte(dr.Body))); err != nil {
139141
return nil, err
140142
}
141-
143+
req.Header = dr.Header
142144
req.Header.Add("Authorization", authString)
143145

144146
client := &http.Client{

0 commit comments

Comments
 (0)