Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Made url-encode polymorhpic, taking string or map as arg.

This makes url-encoding public, & useful for encoding request bodies as
well as query strings.
  • Loading branch information...
1 parent f0fca86 commit 9947078b0acaa2d2bcdf3a966d0cd77b4410209f @pjt pjt committed
Showing with 6 additions and 9 deletions.
  1. +6 −9 src/clojure/http/client.clj
15 src/clojure/http/client.clj
@@ -11,14 +11,11 @@
(defn url-encode
"Wrapper around returning a (UTF-8) URL encoded
-representation of text."
- [text]
- (URLEncoder/encode text "UTF-8"))
-(defn- encode-body-map
- "Turns a map into a URL-encoded string suitable for a request body."
- [body]
- (str-join "&" (map #(str-join "=" (map url-encode %)) body)))
+representation of argument, either a string or map."
+ [arg]
+ (if (map? arg)
+ (str-join \& (map #(str-join \= (map url-encode %)) arg))
+ (URLEncoder/encode (as-str arg) "UTF-8")))
(defn- send-body
[body connection headers]
@@ -36,7 +33,7 @@ representation of text."
(let [out (.getOutputStream connection)]
(string? body) (spit out body)
- (map? body) (spit out (encode-body-map body))
+ (map? body) (spit out (url-encode body))
(instance? InputStream body) (let [bytes (make-array Byte/TYPE 1000)]
(loop [bytes-read (.read body bytes)]
(when (pos? bytes-read)

0 comments on commit 9947078

Please sign in to comment.
Something went wrong with that request. Please try again.