From 21376df84168ce1adc74221fd0ab39fca28b70be Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 23 Dec 2015 12:21:55 +0100 Subject: Use builtin type for Location --- client.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'client.go') diff --git a/client.go b/client.go index 4816c0b..143b79e 100644 --- a/client.go +++ b/client.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "net/http" + "net/url" "regexp" "strconv" "time" @@ -23,7 +24,7 @@ type Client struct { type nextStep struct { Link Links - Location string + Location *url.URL RetryAfter time.Duration } @@ -125,7 +126,7 @@ var linksRe = regexp.MustCompile(`^<(.*)>;rel="(.*)"`) func parseHeader(r *http.Response) nextStep { var ns nextStep - if lo := r.Header.Get("Location"); lo != "" { + if lo, err := r.Location(); err == nil { ns.Location = lo } @@ -181,7 +182,7 @@ func (c *Client) Register(a *Account) error { case http.StatusConflict: // Query Location r = &Registration{Resource: ResRegister} - resp, err = c.post(ns.Location, a, r) + resp, err = c.post(ns.Location.String(), a, r) if err != nil { return err } @@ -194,7 +195,7 @@ func (c *Client) Register(a *Account) error { Contact: a.Contact, Agreement: tos, } - _, err = c.post(ns.Location, a, r) + _, err = c.post(ns.Location.String(), a, r) } } return err -- cgit v1.2.3