Browse files

Added query support to request and resourcefully functions.

  • Loading branch information...
1 parent 1c33d77 commit 1d0f64a5a2900ddacff23d3c459978f7028cc05a @Raynes Raynes committed May 28, 2010
Showing with 12 additions and 4 deletions.
  1. +9 −2 src/clojure_http/client.clj
  2. +3 −2 src/clojure_http/resourcefully.clj
@@ -105,12 +105,19 @@ by a server."
#^String (as-str (val cookie))))
+(defn- queryify
+ "Takes a map of query parameters and turns them into a query string."
+ [url query-map]
+ (if (seq query-map)
+ (apply str url "?" (interpose "&" (for [[k v] query-map] (str k "=" v))))
+ url))
(defn request
"Perform an HTTP request on URL u."
- [u & [method headers cookies body]]
+ [u & [method headers cookies querys body]]
;; This function *should* throw an exception on non-HTTP URLs.
;; This will happen if the cast fails.
- (let [u (url u)
+ (let [u (url (queryify u querys))
#^HttpURLConnection connection
(cast HttpURLConnection (.openConnection u))
method (.toUpperCase #^String (as-str (or method
@@ -37,11 +37,12 @@
`(defn ~method
~(str "Perform HTTP " method " request to url u with specified headers
-map. Cookies will be saved if inside with-cookies block.")
- [u# & [headers# body#]]
+and query map. Cookies will be saved if inside with-cookies block.")
+ [u# & [headers# querys# body#]]
(let [response# (save-cookies (client/request u# ~(str method)
headers# (if *cookies*
+ querys#
(if (error? response#)
(throw ( (error-message response#)))

0 comments on commit 1d0f64a

Please sign in to comment.