aboutsummaryrefslogtreecommitdiff
path: root/client.go
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 /client.go
parentc6261c5ce9537296479b621e91a90e4f57a21734 (diff)
Add next link parser
Diffstat (limited to 'client.go')
-rw-r--r--client.go17
1 files changed, 17 insertions, 0 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
+}