Adding headers to request and fixing case on URI name
diff --git a/authorization.go b/authorization.go index 82e78b7..79cc762 100644 --- a/authorization.go +++ b/authorization.go
@@ -23,7 +23,7 @@ Qop string // unquoted Realm string // quoted Response string // quoted - Uri string // quoted + URI string // quoted Userhash bool // quoted Username string // quoted Username_ string // quoted @@ -40,7 +40,7 @@ Qop: "", Realm: dr.Wa.Realm, Response: "", - Uri: "", + URI: "", Userhash: dr.Wa.Userhash, Username: "", Username_: "", // TODO @@ -61,12 +61,12 @@ ah.Cnonce = ah.hash(fmt.Sprintf("%d:%s:my_value", time.Now().UnixNano(), dr.Username)) - url, err := url.Parse(dr.Uri) + url, err := url.Parse(dr.URI) if err != nil { return nil, err } - ah.Uri = url.RequestURI() + ah.URI = url.RequestURI() ah.Response = ah.computeResponse(dr) return ah, nil @@ -98,12 +98,12 @@ if matched, _ := regexp.MatchString("auth-int", dr.Wa.Qop); matched { ah.Qop = "auth-int" - return fmt.Sprintf("%s:%s:%s", dr.Method, ah.Uri, ah.hash(dr.Body)) + return fmt.Sprintf("%s:%s:%s", dr.Method, ah.URI, ah.hash(dr.Body)) } if dr.Wa.Qop == "auth" || dr.Wa.Qop == "" { ah.Qop = "auth" - return fmt.Sprintf("%s:%s", dr.Method, ah.Uri) + return fmt.Sprintf("%s:%s", dr.Method, ah.URI) } return "" @@ -162,8 +162,8 @@ buffer.WriteString(fmt.Sprintf("response=\"%s\", ", ah.Response)) } - if ah.Uri != "" { - buffer.WriteString(fmt.Sprintf("uri=\"%s\", ", ah.Uri)) + if ah.URI != "" { + buffer.WriteString(fmt.Sprintf("uri=\"%s\", ", ah.URI)) } if ah.Userhash {
diff --git a/digest_auth_client.go b/digest_auth_client.go index 2058e39..321d1d8 100644 --- a/digest_auth_client.go +++ b/digest_auth_client.go
@@ -11,8 +11,9 @@ Body string Method string Password string - Uri string + URI string Username string + Header http.Header Auth *authorization Wa *wwwAuthenticate } @@ -43,7 +44,7 @@ dr.Body = body dr.Method = method dr.Password = password - dr.Uri = uri + dr.URI = uri dr.Username = username return dr } @@ -74,9 +75,10 @@ } var req *http.Request - if req, err = http.NewRequest(dr.Method, dr.Uri, bytes.NewReader([]byte(dr.Body))); err != nil { + if req, err = http.NewRequest(dr.Method, dr.URI, bytes.NewReader([]byte(dr.Body))); err != nil { return nil, err } + req.Header = dr.Header client := &http.Client{ Timeout: 30 * time.Second, @@ -135,10 +137,10 @@ func (dr *DigestRequest) executeRequest(authString string) (resp *http.Response, err error) { var req *http.Request - if req, err = http.NewRequest(dr.Method, dr.Uri, bytes.NewReader([]byte(dr.Body))); err != nil { + if req, err = http.NewRequest(dr.Method, dr.URI, bytes.NewReader([]byte(dr.Body))); err != nil { return nil, err } - + req.Header = dr.Header req.Header.Add("Authorization", authString) client := &http.Client{