Skip to content

Commit 1bb1977

Browse files
committed
added a public url-encode function (thin wrapper around java.net.URLEncoder
1 parent f565569 commit 1bb1977

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/clojure/http/client.clj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
(:use [clojure.contrib.java-utils :only [as-str]]
33
[clojure.contrib.duck-streams :only [read-lines]]
44
[clojure.contrib.str-utils :only [str-join]])
5-
(:import (java.net URL HttpURLConnection)))
5+
(:import (java.net URL HttpURLConnection URLEncoder))))
66

77
(def default-headers {"User-Agent" (str "Clojure/" (clojure-version)
88
" (+http://clojure.org)"),
99
"Connection" "close"})
1010

11+
(defn url-encode
12+
"Wrapper around java.net.URLEncoder returning a (UTF-8) URL encoded
13+
representation of text."
14+
[text]
15+
(URLEncoder/encode text "UTF-8"))
16+
1117
(defn url
1218
"If u is an instance of java.net.URL then returns it without
1319
modification, otherwise tries to instantiate a java.net.URL with
@@ -49,7 +55,7 @@ by a server."
4955
(defn- create-cookie-string
5056
"Returns a string suitable for sending to the server in the
5157
\"Cookie\" header when given a clojure map of cookies."
52-
[cookie-map]
58+
[cookie-map]
5359
(str-join "; " (map (fn [cookie]
5460
(str (as-str (key cookie))
5561
"="

0 commit comments

Comments
 (0)