aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-24 00:49:22 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-24 00:49:22 +0100
commit46e4f83a631af25f0a616c9ffecf3bf715e606e3 (patch)
tree958517fe3d76785d4236662faf6ddff1ddefdb5f /client.go
parentfde15aa0cca6160cfbc698354321a961932a7f86 (diff)
Bikeshading
Diffstat (limited to 'client.go')
-rw-r--r--client.go39
1 files changed, 19 insertions, 20 deletions
diff --git a/client.go b/client.go
index 401fcfb..f10537f 100644
--- a/client.go
+++ b/client.go
@@ -14,18 +14,22 @@ import (
"github.com/mgutz/ansi"
)
-type Links map[string]string
-
// Client ...
type Client struct {
Directory
nonce chan string
}
-type nextStep struct {
- Link Links
- Location *url.URL
- RetryAfter time.Duration
+var errNoNonces = errors.New("out of nonces")
+
+// Nonce implements jose nonce provider
+func (c Client) Nonce() (string, error) {
+ select {
+ case nonce := <-c.nonce:
+ return nonce, nil
+ default:
+ return "", errNoNonces
+ }
}
func (c Client) replyNonce(r *http.Response) {
@@ -47,18 +51,6 @@ func NewClient(directory string) (*Client, error) {
return c, json.NewDecoder(resp.Body).Decode(&c.Directory)
}
-var errNoNonces = errors.New("out of nonces")
-
-// Nonce implements jose nonce provider
-func (c Client) Nonce() (string, error) {
- select {
- case nonce := <-c.nonce:
- return nonce, nil
- default:
- return "", errNoNonces
- }
-}
-
// Important header fields
//
// Replay-Nonce each response, required for next request
@@ -85,8 +77,7 @@ func (c *Client) post(uri string, s Signer, v interface{}) (*http.Response, erro
}
log.Println(ansi.Color("POST", "red+b"), uri, string(body))
- s.Init(c)
- signed, err := s.Sign(body)
+ signed, err := s.Sign(body, c)
if err != nil {
return nil, err
}
@@ -121,6 +112,14 @@ func (c *Client) post(uri string, s Signer, v interface{}) (*http.Response, erro
//return json.NewDecoder(resp.Body).Decode(v)
}
+type Links map[string]string
+
+type nextStep struct {
+ Link Links
+ Location *url.URL
+ RetryAfter time.Duration
+}
+
var linksRe = regexp.MustCompile(`^<(.*)>;rel="(.*)"`)
func parseHeader(r *http.Response) nextStep {