From bc3617c26abcd88fee550360ade3429d2de47133 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 28 Nov 2015 19:14:15 +0100 Subject: Add next link parser --- client.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'client.go') 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 +} -- cgit v1.2.3