From beb07b9563b9370fb0123b3ed07ff319e2ebe835 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 6 Jan 2016 01:32:53 +0100 Subject: Embed http.Client --- provider.go | 19 ++++++------------- 1 file 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 } -- cgit v1.2.3