From 255f511cf92fe50853b21101db4ed608628244ee Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Fri, 3 Feb 2012 20:22:21 -0700 Subject: [PATCH] clean up whitespace A clean codebase is a happy codebase --- src/clj_http/client.clj | 16 ++-------------- src/clj_http/core.clj | 4 ++-- test/clj_http/test/client.clj | 17 ++++------------- test/clj_http/test/cookies.clj | 1 - test/clj_http/test/core.clj | 26 ++++++++------------------ 5 files changed, 16 insertions(+), 48 deletions(-) diff --git a/src/clj_http/client.clj b/src/clj_http/client.clj index 958105c7..79849043 100644 --- a/src/clj_http/client.clj +++ b/src/clj_http/client.clj @@ -27,7 +27,6 @@ :user-info (.getUserInfo url-parsed) :query-string (.getQuery url-parsed)})) - (def unexceptional-status? #{200 201 202 203 204 205 206 207 300 301 302 303 307}) @@ -58,7 +57,6 @@ :else resp)))) - (defn wrap-decompression [client] (fn [req] (if (get-in req [:headers "Accept-Encoding"]) @@ -67,13 +65,10 @@ resp-c (client req-c)] (case (or (get-in resp-c [:headers "Content-Encoding"]) (get-in resp-c [:headers "content-encoding"])) - "gzip" - (update resp-c :body util/gunzip) - "deflate" - (update resp-c :body util/inflate) + "gzip" (update resp-c :body util/gunzip) + "deflate" (update resp-c :body util/inflate) resp-c))))) - (defn wrap-output-coercion [client] (fn [{:keys [as] :as req}] (let [{:keys [body] :as resp} (client req)] @@ -120,7 +115,6 @@ (assoc resp :body (String. #^"[B" body "UTF-8"))) resp)))) - (defn wrap-input-coercion [client] (fn [{:keys [body body-encoding length] :as req}] (if body @@ -147,7 +141,6 @@ (client req)) (client req)))) - (defn content-type-value [type] (if (keyword? type) (str "application/" (name type)) @@ -160,7 +153,6 @@ (content-type-value content-type)))) (client req)))) - (defn wrap-accept [client] (fn [{:keys [accept] :as req}] (if accept @@ -169,7 +161,6 @@ (content-type-value accept)))) (client req)))) - (defn accept-encoding-value [accept-encoding] (str/join ", " (map name accept-encoding))) @@ -181,7 +172,6 @@ (accept-encoding-value accept-encoding)))) (client req)))) - (defn generate-query-string [params] (str/join "&" (mapcat (fn [[k v]] @@ -195,7 +185,6 @@ (util/url-encode (str v)))])) params))) - (defn wrap-query-params [client] (fn [{:keys [query-params] :as req}] (if query-params @@ -204,7 +193,6 @@ (generate-query-string query-params)))) (client req)))) - (defn basic-auth-value [basic-auth] (let [basic-auth (if (string? basic-auth) basic-auth diff --git a/src/clj_http/core.clj b/src/clj_http/core.clj index 1c712472..a361f0e0 100644 --- a/src/clj_http/core.clj +++ b/src/clj_http/core.clj @@ -204,8 +204,8 @@ (ByteArrayEntity. body)))))) (when debug (println "Request:") - (clojure.pprint/pprint (assoc req :body (format "... %s bytes ..." - (count (:body req))))) + (clojure.pprint/pprint + (assoc req :body (format "... %s bytes ..." (count (:body req))))) (println "HttpRequest:") (clojure.pprint/pprint (bean http-req))) (let [http-resp (.execute http-client http-req) diff --git a/test/clj_http/test/client.clj b/test/clj_http/test/client.clj index e833bd68..1605f35d 100644 --- a/test/clj_http/test/client.clj +++ b/test/clj_http/test/client.clj @@ -19,7 +19,6 @@ (is (= "close" (get-in resp [:headers "connection"]))) (is (= "get" (:body resp))))) - (defn is-passed [middleware req] (let [client (middleware identity)] (is (= req (client req))))) @@ -28,7 +27,6 @@ (let [client (middleware identity)] (is (= req-out (client req-in))))) - (deftest redirect-on-get (let [client (fn [req] (if (= "foo.com" (:server-name req)) @@ -89,10 +87,10 @@ resp (e-client {:throw-exceptions false})] (is (= 500 (:status resp))))) - (deftest apply-on-compressed (let [client (fn [req] - (is (= "gzip, deflate" (get-in req [:headers "Accept-Encoding"]))) + (is (= "gzip, deflate" + (get-in req [:headers "Accept-Encoding"]))) {:body (util/gzip (util/utf8-bytes "foofoofoo")) :headers {"Content-Encoding" "gzip"}}) c-client (client/wrap-decompression client) @@ -101,7 +99,8 @@ (deftest apply-on-deflated (let [client (fn [req] - (is (= "gzip, deflate" (get-in req [:headers "Accept-Encoding"]))) + (is (= "gzip, deflate" + (get-in req [:headers "Accept-Encoding"]))) {:body (util/deflate (util/utf8-bytes "barbarbar")) :headers {"Content-Encoding" "deflate"}}) c-client (client/wrap-decompression client) @@ -113,7 +112,6 @@ resp (c-client {:uri "/foo"})] (is (= "foo" (:body resp))))) - (deftest apply-on-accept (is-applied client/wrap-accept {:accept :json} @@ -123,7 +121,6 @@ (is-passed client/wrap-accept {:uri "/foo"})) - (deftest apply-on-accept-encoding (is-applied client/wrap-accept-encoding {:accept-encoding [:identity :gzip]} @@ -133,7 +130,6 @@ (is-passed client/wrap-accept-encoding {:uri "/foo"})) - (deftest apply-on-output-coercion (let [client (fn [req] {:body (util/utf8-bytes "foo")}) o-client (client/wrap-output-coercion client) @@ -150,7 +146,6 @@ resp (o-client {:uri "/foo" :as :byte-array})] (is (= :thebytes (:body resp))))) - (deftest apply-on-input-coercion (let [i-client (client/wrap-input-coercion identity) resp (i-client {:body "foo"}) @@ -166,7 +161,6 @@ (is-passed client/wrap-input-coercion {:body nil})) - (deftest apply-on-content-type (is-applied client/wrap-content-type {:content-type :json} @@ -176,7 +170,6 @@ (is-passed client/wrap-content-type {:uri "/foo"})) - (deftest apply-on-query-params (is-applied client/wrap-query-params {:query-params {"foo" "bar" "dir" "<<"}} @@ -186,7 +179,6 @@ (is-passed client/wrap-query-params {:uri "/foo"})) - (deftest apply-on-basic-auth (is-applied client/wrap-basic-auth {:basic-auth ["Aladdin" "open sesame"]} @@ -197,7 +189,6 @@ (is-passed client/wrap-basic-auth {:uri "/foo"})) - (deftest apply-on-method (let [m-client (client/wrap-method identity) echo (m-client {:key :val :method :post})] diff --git a/test/clj_http/test/cookies.clj b/test/clj_http/test/cookies.clj index 6a139ff3..fb3115b1 100644 --- a/test/clj_http/test/cookies.clj +++ b/test/clj_http/test/cookies.clj @@ -209,4 +209,3 @@ {"set-cookie" "example-cookie=example-value;Domain=.example.com;Path=/"}})) {:cookies {:a {:value "1"} :b {:value "2"}}})))) - diff --git a/test/clj_http/test/core.clj b/test/clj_http/test/core.clj index 6054e51d..2c74276c 100644 --- a/test/clj_http/test/core.clj +++ b/test/clj_http/test/core.clj @@ -164,31 +164,21 @@ (into-array BasicHeader (map (fn [[name value]] (BasicHeader. name value)) - headers)) - nil)] - (is (= (core/parse-headers iterator) - expected))) + headers)) nil)] + (is (= (core/parse-headers iterator) expected))) - [] - {} + [] {} - [["Set-Cookie" "one"]] - {"set-cookie" "one"} + [["Set-Cookie" "one"]] {"set-cookie" "one"} - [["Set-Cookie" "one"] - ["set-COOKIE" "two"]] + [["Set-Cookie" "one"] ["set-COOKIE" "two"]] {"set-cookie" ["one" "two"]} - [["Set-Cookie" "one"] - ["serVer" "some-server"] - ["set-cookie" "two"]] - {"set-cookie" ["one" "two"] - "server" "some-server"})) + [["Set-Cookie" "one"] ["serVer" "some-server"] ["set-cookie" "two"]] + {"set-cookie" ["one" "two"] "server" "some-server"})) (deftest ^{:integration true} t-streaming-response (run-server) - (let [stream (:body (request {:request-method :get - :uri "/get" - :as :stream})) + (let [stream (:body (request {:request-method :get :uri "/get" :as :stream})) body (slurp stream)] (is (= "get" body))))