Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
clean up whitespace
Browse files Browse the repository at this point in the history
A clean codebase is a happy codebase
  • Loading branch information
dakrone committed Feb 4, 2012
1 parent b53f14d commit 255f511
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 48 deletions.
16 changes: 2 additions & 14 deletions src/clj_http/client.clj
Expand Up @@ -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})

Expand Down Expand Up @@ -58,7 +57,6 @@
:else
resp))))


(defn wrap-decompression [client]
(fn [req]
(if (get-in req [:headers "Accept-Encoding"])
Expand All @@ -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)]
Expand Down Expand Up @@ -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
Expand All @@ -147,7 +141,6 @@
(client req))
(client req))))


(defn content-type-value [type]
(if (keyword? type)
(str "application/" (name type))
Expand All @@ -160,7 +153,6 @@
(content-type-value content-type))))
(client req))))


(defn wrap-accept [client]
(fn [{:keys [accept] :as req}]
(if accept
Expand All @@ -169,7 +161,6 @@
(content-type-value accept))))
(client req))))


(defn accept-encoding-value [accept-encoding]
(str/join ", " (map name accept-encoding)))

Expand All @@ -181,7 +172,6 @@
(accept-encoding-value accept-encoding))))
(client req))))


(defn generate-query-string [params]
(str/join "&"
(mapcat (fn [[k v]]
Expand All @@ -195,7 +185,6 @@
(util/url-encode (str v)))]))
params)))


(defn wrap-query-params [client]
(fn [{:keys [query-params] :as req}]
(if query-params
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/clj_http/core.clj
Expand Up @@ -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)
Expand Down
17 changes: 4 additions & 13 deletions test/clj_http/test/client.clj
Expand Up @@ -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)))))
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -113,7 +112,6 @@
resp (c-client {:uri "/foo"})]
(is (= "foo" (:body resp)))))


(deftest apply-on-accept
(is-applied client/wrap-accept
{:accept :json}
Expand All @@ -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]}
Expand All @@ -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)
Expand All @@ -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"})
Expand All @@ -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}
Expand All @@ -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" "<<"}}
Expand All @@ -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"]}
Expand All @@ -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})]
Expand Down
1 change: 0 additions & 1 deletion test/clj_http/test/cookies.clj
Expand Up @@ -209,4 +209,3 @@
{"set-cookie"
"example-cookie=example-value;Domain=.example.com;Path=/"}}))
{:cookies {:a {:value "1"} :b {:value "2"}}}))))

26 changes: 8 additions & 18 deletions test/clj_http/test/core.clj
Expand Up @@ -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))))

0 comments on commit 255f511

Please sign in to comment.