Permalink
Browse files

Allow coercing response :body as string of arbitrary type

  • Loading branch information...
1 parent 36641c0 commit ad47102a4be8737466423dceb82e428f7b612ede @dakrone dakrone committed Jan 4, 2012
Showing with 5 additions and 1 deletion.
  1. +2 −0 Readme.md
  2. +3 −1 src/clj_http/client.clj
View
@@ -45,6 +45,8 @@ More example requests:
(client/get "http://site.com/search" {:query-params {"q" "foo, bar"}})
(client/get "http://site.com/favicon.ico" {:as :byte-array})
+;; Coerce as something other than UTF-8 string
+(client/get "http://site.com/string.txt" {:as "UTF-16"})
(client/post "http://site.com/api"
{:basic-auth ["user" "pass"]
View
@@ -76,7 +76,9 @@
(cond
(or (nil? body) (= :byte-array as))
resp
- (nil? as)
+ (string? as)
+ (assoc resp :body (String. #^"[B" body as))
+ :else
(assoc resp :body (String. #^"[B" body "UTF-8"))))))

0 comments on commit ad47102

Please sign in to comment.