Skip to content

Commit

Permalink
Allow coercing response :body as string of arbitrary type
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone committed Jan 4, 2012
1 parent 36641c0 commit ad47102
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 3 additions & 1 deletion src/clj_http/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"))))))


Expand Down

0 comments on commit ad47102

Please sign in to comment.