 (ns picard.middleware.retry
+  (:require [clojure.contrib.logging :as log])
   (:use [picard helpers utils]))
 
 (defrecord State [app upstream retries sent-body? opts])

  [app opts]
  (let [opts (merge default-options opts)]
    (State. app nil (:retries opts) false opts)))

(defn- attempt-request
  [state downstream request current-state]

    :as upstream
    (swap! state #(assoc % :upstream upstream))
    (upstream :request request))))

(defn- retry-request
  [state downstream request current-state]
  (log/info (str "retrying request: " (request-url request)))
  (attempt-request state downstream request current-state))

(defn retry
  ([app] (retry app {}))
