aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-06 11:04:50 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-06 11:04:50 +0100
commit4c01872714a54959d32cce1a651756019d185f32 (patch)
tree31334c1cb53cd98e8c92fe9b9733ab4d84be03b1 /client.go
parent56eb87944ec5e64daff1d7d0f80e9a60eb12bf96 (diff)
Parse Retry-After
Diffstat (limited to 'client.go')
-rw-r--r--client.go27
1 files changed, 23 insertions, 4 deletions
diff --git a/client.go b/client.go
index a78e437..a64f0d5 100644
--- a/client.go
+++ b/client.go
@@ -7,8 +7,14 @@ import (
"net/http"
"net/textproto"
"regexp"
+ "strconv"
+ "time"
)
+type Solver interface {
+ Solve()
+}
+
type NonceSigner interface {
Sign([]byte) ([]byte, error)
parseNonce(*http.Response)
@@ -30,7 +36,7 @@ func Get(s NonceSigner, uri string, v interface{}) error {
//
// Replay-Nonce each response, required for next request
// Link links to next stage
-// Retry-After pooling interval
+// Retry-After polling interval
// Action Request Response
//
@@ -66,16 +72,16 @@ func Post(s NonceSigner, uri string, v interface{}) (*http.Response, error) {
return nil, handleError(resp)
}
- log.Printf("%+v\n", parseLinks(resp))
+ log.Printf("%+v\n", link(resp))
return resp, nil
}
type Links map[string]string
-func parseLinks(r *http.Response) Links {
+func link(r *http.Response) Links {
links := make(Links)
- key := textproto.CanonicalMIMEHeaderKey("link")
+ key := textproto.CanonicalMIMEHeaderKey("Link")
reg := regexp.MustCompile(`^<(.*)>;rel="(.*)"`)
for _, l := range r.Header[key] {
re := reg.FindStringSubmatch(l)
@@ -85,3 +91,16 @@ func parseLinks(r *http.Response) Links {
}
return links
}
+
+func retryAfter(r *http.Response) time.Duration {
+ if ra := r.Header.Get("Retry-After"); ra != "" {
+ if i, err := strconv.Atoi(ra); err == nil {
+ return time.Duration(i) * time.Second
+ }
+ }
+ return time.Second
+}
+
+func replyNonce(r *http.Response) string {
+ return r.Header.Get("Replay-Nonce")
+}