aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-21 01:23:19 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-21 01:23:19 +0100
commitacb9c5d087924b77d83a3fc65813c19b65e90298 (patch)
treef6eae837d5a28840442cb28e6da7cfdf36ffdfcf /client.go
parentf37c6e605107764cd1fd6d3fbd3d975ea8a3b8b8 (diff)
Return uri to post
Diffstat (limited to 'client.go')
-rw-r--r--client.go35
1 files changed, 18 insertions, 17 deletions
diff --git a/client.go b/client.go
index 4737995..4cb0aa9 100644
--- a/client.go
+++ b/client.go
@@ -24,8 +24,8 @@ type Client struct {
}
// NewClient fetches directory and initializes nonce
-func NewClient(uri string) (*Client, error) {
- resp, err := http.Get(uri)
+func NewClient(directory string) (*Client, error) {
+ resp, err := http.Get(directory)
if err != nil {
return nil, err
}
@@ -39,7 +39,7 @@ func NewClient(uri string) (*Client, error) {
return c, nil
}
-var errNoNonces = errors.New("No nonces available")
+var errNoNonces = errors.New("out of nonces")
// Nonce implements jose nonce provider
func (c Client) Nonce() (string, error) {
@@ -70,21 +70,21 @@ func (c Client) Nonce() (string, error) {
// request is used for
// new-reg, new-authz, challenge, new-cert
-func (c *Client) post(s Signer, v interface{}) error {
+func (c *Client) post(uri string, s Signer, v interface{}) (*http.Response, error) {
body, err := json.Marshal(v)
if err != nil {
- return err
+ return nil, err
}
log.Println("POST", string(body))
signed, err := s.Sign(body, c)
if err != nil {
- return err
+ return nil, err
}
- resp, err := http.Post(c.Location, "application/jose+json", signed)
+ resp, err := http.Post(uri, "application/jose+json", signed)
if err != nil {
- return err
+ return nil, err
}
defer resp.Body.Close()
c.parseHeader(resp)
@@ -95,21 +95,21 @@ func (c *Client) post(s Signer, v interface{}) error {
var p Problem
err = json.NewDecoder(resp.Body).Decode(&p)
if err != nil {
- return err
+ return resp, err
}
if err, ok := urnErrors[p.Type]; ok {
p.Err = err
}
- return p
+ return resp, p
}
// DEBUG
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
- return err
+ return resp, err
}
log.Println("RESPONSE", string(body))
- return json.Unmarshal(body, v)
+ return resp, json.Unmarshal(body, v)
//return json.NewDecoder(resp.Body).Decode(v)
}
@@ -164,8 +164,8 @@ func (c *Client) Register(a *Account) (*Registration, error) {
Resource: ResNewReg,
Contact: a.Contact,
}
- c.Location = c.Dir.NewReg
- return r, c.post(a, r)
+ _, err := c.post(c.Dir.NewReg, a, r)
+ return r, err
}
// Agree to TOS
@@ -180,7 +180,8 @@ func (c *Client) Agree(a *Account) (*Registration, error) {
Agreement: tos,
}
log.Println("TOS", tos)
- return r, c.post(a, r)
+ _, err := c.post(c.Location, a, r)
+ return r, err
}
func (c *Client) Authorize(a *Account, domain string) (*Authorization, error) {
@@ -191,8 +192,8 @@ func (c *Client) Authorize(a *Account, domain string) (*Authorization, error) {
Value: domain,
},
}
- c.Location = c.Dir.NewAuthz
- return r, c.post(a, r)
+ _, err := c.post(c.Dir.NewAuthz, a, r)
+ return r, err
}
func (c Client) String() string {