Skip to content

Commit c917372

Browse files
Richard NewmanRichard Newman
authored andcommitted
Add set-system-proxy\! function, allowing the use of a proxy server in HTTP requests.
1 parent 01f52c2 commit c917372

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/clojure/http/client.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
" (+http://clojure.org)"),
1010
"Connection" "close"})
1111

12+
(defn set-system-proxy!
13+
"Java's HttpURLConnection cannot do per-request proxying. Instead,
14+
system properties are used. This function mutates the global setting.
15+
For per-request proxying, use the Apache HTTP client."
16+
[#^String host port]
17+
(doto (System/getProperties)
18+
(.setProperty "http.proxyHost" host)
19+
(.setProperty "http.proxyPort" (str port)))
20+
nil)
21+
1222
(defn url-encode
1323
"Wrapper around java.net.URLEncoder returning a (UTF-8) URL encoded
1424
representation of argument, either a string or map."

0 commit comments

Comments
 (0)