diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-08-14 15:22:28 -0400 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-08-14 15:22:28 -0400 |
commit | 54ee3b6fc9d625bb476f38b096f80b791cfa9b65 (patch) | |
tree | cdde3ac0b5a62eaaed9a401b0d10c273505fa8fc | |
parent | 3bd1a3506de189040fdbc26be9c4eba308d98a06 (diff) |
http/agent.clj: added predicates to test response code ranges
Renamed "request-success?" to "success?"
-rw-r--r-- | src/clojure/contrib/http/agent.clj | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/clojure/contrib/http/agent.clj b/src/clojure/contrib/http/agent.clj index 3318396b..cbb4b725 100644 --- a/src/clojure/contrib/http/agent.clj +++ b/src/clojure/contrib/http/agent.clj @@ -177,7 +177,37 @@ (thisfn (inc i)))))] (lazy-seq (f 0)))) -(defn response-success? +(defn- response-in-range? [digit http-agnt] + (= digit (unchecked-divide (.getResponseCode (::connection @http-agnt)) + 100))) + +(defn success? "Returns true if the HTTP response code was in the 200-299 range." [http-agnt] - (connection-success? (::connection @http-agnt))) + (response-in-range? 2 http-agnt)) + +(defn redirect? + "Returns true if the HTTP response code was in the 300-399 range. + + Note: if the :follow-redirects option was true (the default), + redirects will be followed automatically and a the agent will never + return a 3xx response code." + [http-agnt] + (response-in-range? 3 http-agnt)) + +(defn client-error? + "Returns true if the HTTP response code was in the 400-499 range." + [http-agnt] + (response-in-range? 4 http-agnt)) + +(defn server-error? + "Returns true if the HTTP response code was in the 500-599 range." + [http-agnt] + (response-in-range? 5 http-agnt)) + +(defn error? + "Returns true if the HTTP response code was in the 400-499 range OR + the 500-599 range." + [http-agnt] + (or (client-error? http-agnt) + (server-error? http-agnt))) |