aboutsummaryrefslogtreecommitdiff
path: root/provider.go
diff options
context:
space:
mode:
Diffstat (limited to 'provider.go')
-rw-r--r--provider.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/provider.go b/provider.go
index 712470a..1a79b23 100644
--- a/provider.go
+++ b/provider.go
@@ -16,6 +16,7 @@ import (
type Provider struct {
Directory
nonces chan string
+ http.Client
}
var (
@@ -38,7 +39,7 @@ func (p Provider) Nonce() (string, error) {
// NewProvider fetches directory and initializes nonce
func NewProvider(directory string) (*Provider, error) {
p := &Provider{nonces: make(chan string, 10)}
- resp, err := http.Get(directory)
+ resp, err := p.Get(directory)
if err != nil {
return nil, err
}
@@ -74,7 +75,7 @@ func (p *Provider) post(uri string, s Signer, v interface{}) (*http.Response, er
if err != nil {
return nil, err
}
- return http.Post(uri, "application/json", signed)
+ return p.Post(uri, "application/json", signed)
}
type nextStep struct {
@@ -86,7 +87,6 @@ var linksRe = regexp.MustCompile(`^<(.*)>;rel="(.*)"`)
func (p *Provider) parse(resp *http.Response, v interface{}) (ns nextStep, err error) {
if lo, _ := resp.Location(); lo != nil {
- log.Println(lo)
ns.Location = lo.String()
}
@@ -112,12 +112,7 @@ func (p *Provider) parse(resp *http.Response, v interface{}) (ns nextStep, err e
switch resp.Header.Get("Content-Type") {
case "application/problem+json":
- var p Problem
- if err = json.Unmarshal(body, &p); err != nil {
- return
- }
- p.Err = urnErrors[p.Type]
- err = p
+ err = problem(resp)
case "application/json":
err = json.Unmarshal(body, v)
case "application/pkix-cert":
@@ -134,9 +129,7 @@ func problem(resp *http.Response) error {
if err := json.NewDecoder(resp.Body).Decode(&p); err != nil {
return err
}
- if err, ok := urnErrors[p.Type]; ok {
- p.Err = err
- }
+ p.Err = urnErrors[p.Type]
return p
}
@@ -283,7 +276,7 @@ func (p *Provider) Authorize(s ThumbSigner, domain string) error {
func (p *Provider) queryStatus(url string, done chan bool) error {
r := &Challenge{}
- resp, err := http.Get(url)
+ resp, err := p.Get(url)
if err != nil {
return err
}