aboutsummaryrefslogtreecommitdiff
path: root/src/clojure
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure')
-rw-r--r--src/clojure/contrib/http/agent.clj35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/clojure/contrib/http/agent.clj b/src/clojure/contrib/http/agent.clj
index d1007475..e45d8880 100644
--- a/src/clojure/contrib/http/agent.clj
+++ b/src/clojure/contrib/http/agent.clj
@@ -89,11 +89,17 @@
::state ::created})]
(send-off a do-http-agent-request opts)))))
-(defn response-body-bytes [a]
+(defn response-body-bytes
+ "Returns a Java byte array of the content returned by the server."
+ [a]
(when (= (::state @a) ::completed)
(::response-body-bytes @a)))
-(defn response-body-str [a]
+(defn response-body-str
+ "Returns the HTTP response body as a string. The string will be
+ created using the encoding specified by the server, or
+ *default-encoding* if it is not specified."
+ [a]
(let [da @a]
(when (= (::state da) ::completed)
(let [conn (::connection da)
@@ -102,14 +108,25 @@
duck/*default-encoding*)]
(String. bytes encoding)))))
-(defn response-status [a]
- (.getResponseCode (::connection @a)))
-
-(defn response-message [a]
- (.getResponseMessage (::connection @a)))
+(defn response-status
+ "Returns the Integer response status code (e.g. 200, 404) for this request."
+ [a]
+ (when (= (::state @a) ::completed)
+ (.getResponseCode (::connection @a))))
-(defn response-headers [a]
- (.getHeaderFields (::connection @a)))
+(defn response-message
+ "Returns the HTTP response message (e.g. 'Not Found'), for this request."
+ [a]
+ (when (= (::state @a) ::completed)
+ (.getResponseMessage (::connection @a))))
+
+(defn response-headers
+ "Returns a String=>String map of HTTP response headers. If a header
+ appears more than once, only the last value is returned."
+ [a]
+ (reduce (fn [m [k v]]
+ (assoc m k (last v)))
+ {} (.getHeaderFields (::connection @a))))
(defn response-headers-seq
"Returns the HTTP response headers in order as a sequence of