aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-28 19:14:15 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-28 19:14:15 +0100
commitbc3617c26abcd88fee550360ade3429d2de47133 (patch)
treedcd7754bd954339998e74fc99e1e2e9af1ac4c9c
parentc6261c5ce9537296479b621e91a90e4f57a21734 (diff)
Add next link parser
-rw-r--r--client.go17
-rw-r--r--messages.go9
2 files changed, 24 insertions, 2 deletions
diff --git a/client.go b/client.go
index 06bb907..0eed71f 100644
--- a/client.go
+++ b/client.go
@@ -3,7 +3,10 @@ package acme
import (
"bytes"
"encoding/json"
+ "log"
"net/http"
+ "net/textproto"
+ "regexp"
"github.com/square/go-jose"
)
@@ -40,6 +43,7 @@ func Post(s Signer, uri string, v interface{}) (*http.Response, error) {
return nil, err
}
nonces.parse(resp)
+ log.Printf("%+v\n", parseLinks(resp))
if resp.StatusCode >= http.StatusBadRequest {
return nil, handleError(resp)
@@ -60,3 +64,16 @@ func Sign(acc Account, body []byte) (string, error) {
}
return obj.FullSerialize(), nil
}
+
+func parseLinks(r *http.Response) map[string]string {
+ links := make(map[string]string)
+ key := textproto.CanonicalMIMEHeaderKey("link")
+ reg := regexp.MustCompile(`^<(.*)>;rel="(.*)"`)
+ for _, l := range r.Header[key] {
+ re := reg.FindStringSubmatch(l)
+ if len(re) == 3 {
+ links[re[2]] = re[1]
+ }
+ }
+ return links
+}
diff --git a/messages.go b/messages.go
index 511c713..26e4f2b 100644
--- a/messages.go
+++ b/messages.go
@@ -41,9 +41,14 @@ type Key struct {
N string `json:"n"`
}
-// Authorization Objects
+// Authorization request
type Authorization struct {
- Resource string `json:"resource"`
+ Resource string `json:"resource"`
+ Identifier Identifier `json:"identifier"`
+}
+
+// AuthorizationResp Objects
+type AuthorizationResp struct {
Identifier Identifier `json:"identifier"`
Status string `json:"status,omitemtpy"` // valid
Expires string `json:"expires,omitempty"` // 2006-01-02