diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2009-08-14 15:08:11 -0400 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2009-08-14 15:08:11 -0400 |
commit | 3bd1a3506de189040fdbc26be9c4eba308d98a06 (patch) | |
tree | 75b08ed80cf53264634cedd5593d5fa8b2a21fab | |
parent | 05cf6c1e991a9db416a51f1ff5cc8ff2bccac15a (diff) |
http/agent.clj: allow encoding argument on response-body-str
-rw-r--r-- | src/clojure/contrib/http/agent.clj | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/clojure/contrib/http/agent.clj b/src/clojure/contrib/http/agent.clj index 3fd5c2e9..3318396b 100644 --- a/src/clojure/contrib/http/agent.clj +++ b/src/clojure/contrib/http/agent.clj @@ -126,17 +126,22 @@ (::response-body-bytes @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) - bytes (::response-body-bytes da) - encoding (or (.getContentEncoding conn) - duck/*default-encoding*)] - (String. bytes encoding))))) + "Returns the HTTP response body as a string, using the given + encoding. + + If no encoding is given, uses the encoding specified in the server + headers, or clojure.contrib.duck-streams/*default-encoding* if it is + not specified." + ([http-agnt] + (response-body-str http-agnt + (or (.getContentEncoding (::connection @http-agnt)) + duck/*default-encoding*))) + ([http-agnt encoding] + (let [a @http-agnt] + (when (= (::state a) ::completed) + (let [conn (::connection a) + bytes (::response-body-bytes a)] + (String. bytes encoding)))))) (defn response-status "Returns the Integer response status code (e.g. 200, 404) for this request." |