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 +++++++++++++++++ messages.go | 9 +++++++-- 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 -- cgit v1.2.3