diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-08-14 14:58:03 -0400 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-08-14 14:58:03 -0400 |
commit | 05cf6c1e991a9db416a51f1ff5cc8ff2bccac15a (patch) | |
tree | b3f9954fd890146e74487e22f7edb449ac1bdd0a | |
parent | 5f3988ffe6eb894448cbdc2bd4ec8b01ba2e10ce (diff) |
http/agent.clj: added response-success?
-rw-r--r-- | src/clojure/contrib/http/agent.clj | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/clojure/contrib/http/agent.clj b/src/clojure/contrib/http/agent.clj index ca0edc79..3fd5c2e9 100644 --- a/src/clojure/contrib/http/agent.clj +++ b/src/clojure/contrib/http/agent.clj @@ -24,7 +24,7 @@ (doseq [[name value] (:headers options)] (.setRequestProperty conn name value))) -(defn- success? [conn] +(defn- connection-success? [conn] ;; Is the response in the 2xx range? (= 2 (unchecked-divide (.getResponseCode conn) 100))) @@ -32,7 +32,7 @@ (let [conn (::connection state)] (setup-http-connection conn options) (c/start-http-connection conn (:body options)) - (let [bytes (if (success? conn) + (let [bytes (if (connection-success? conn) (duck/to-byte-array (.getInputStream conn)) (duck/to-byte-array (.getErrorStream conn)))] (.disconnect conn) @@ -51,7 +51,7 @@ (defn- completed-watch [success-fn failure-fn key http-agnt old-state new-state] (when (and (= (::state new-state) ::completed) (not= (::state old-state) ::completed)) - (if (success? (::connection new-state)) + (if (connection-success? (::connection new-state)) (when success-fn (success-fn http-agnt)) (when failure-fn (failure-fn http-agnt))))) @@ -171,3 +171,8 @@ (cons [(.getHeaderFieldKey conn i) value] (thisfn (inc i)))))] (lazy-seq (f 0)))) + +(defn response-success? + "Returns true if the HTTP response code was in the 200-299 range." + [http-agnt] + (connection-success? (::connection @http-agnt))) |