Skip to content

Commit 0ad8301

Browse files
committed
Apply bikeshed changes
Just reformatting, no actual code changes
1 parent 322cba6 commit 0ad8301

File tree

7 files changed

+84
-52
lines changed

7 files changed

+84
-52
lines changed

src/clj_http/client.clj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,22 +462,26 @@
462462
(read-string (String. ^"[B" body charset)))))))
463463

464464
(defn coerce-transit-body
465-
[{:keys [transit-opts coerce] :as request} {:keys [body status] :as resp} type & [charset]]
465+
[{:keys [transit-opts coerce] :as request}
466+
{:keys [body status] :as resp} type & [charset]]
466467
(let [^String charset (or charset (-> resp :content-type-params :charset)
467468
"UTF-8")
468469
body (util/force-byte-array body)]
469470
(if-not (empty? body)
470471
(if transit-enabled?
471472
(cond
472473
(= coerce :always)
473-
(assoc resp :body (parse-transit (ByteArrayInputStream. body) type transit-opts))
474+
(assoc resp :body (parse-transit
475+
(ByteArrayInputStream. body) type transit-opts))
474476

475477
(and (unexceptional-status? status)
476478
(or (nil? coerce) (= coerce :unexceptional)))
477-
(assoc resp :body (parse-transit (ByteArrayInputStream. body) type transit-opts))
479+
(assoc resp :body (parse-transit
480+
(ByteArrayInputStream. body) type transit-opts))
478481

479482
(and (not (unexceptional-status? status)) (= coerce :exceptional))
480-
(assoc resp :body (parse-transit (ByteArrayInputStream. body) type transit-opts))
483+
(assoc resp :body (parse-transit
484+
(ByteArrayInputStream. body) type transit-opts))
481485

482486
:else (assoc resp :body (String. ^"[B" body charset)))
483487
(assoc resp :body (String. ^"[B" body charset)))

src/clj_http/conn_mgr.clj

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
(defn ^SSLConnectionSocketFactory SSLGenericSocketFactory
5353
"Given a function that returns a new socket, create an
5454
SSLConnectionSocketFactory that will use that socket."
55-
([socket-factory] (SSLGenericSocketFactory socket-factory (SSLContexts/createDefault)))
55+
([socket-factory]
56+
(SSLGenericSocketFactory socket-factory (SSLContexts/createDefault)))
5657
([socket-factory ^SSLContext ssl-context]
5758
(proxy [SSLConnectionSocketFactory] [ssl-context]
5859
(connectSocket [timeout socket host remoteAddress localAddress context]
@@ -110,14 +111,22 @@
110111
(defn make-socks-proxied-conn-manager
111112
"Given an optional hostname and a port, create a connection manager that's
112113
proxied using a SOCKS proxy."
113-
([^String hostname ^Integer port] (make-socks-proxied-conn-manager hostname port {}))
114-
([^String hostname ^Integer port {:keys [keystore keystore-type keystore-pass trust-store trust-store-type trust-store-pass] :as opts}]
114+
([^String hostname ^Integer port]
115+
(make-socks-proxied-conn-manager hostname port {}))
116+
([^String hostname ^Integer port
117+
{:keys [keystore keystore-type keystore-pass
118+
trust-store trust-store-type trust-store-pass] :as opts}]
115119
(let [socket-factory #(socks-proxied-socket hostname port)
116-
ssl-context (when (some (complement nil?) [keystore keystore-type keystore-pass trust-store trust-store-type trust-store-pass])
117-
(-> opts get-keystore-context-verifier :context))
120+
ssl-context (when
121+
(some (complement nil?)
122+
[keystore keystore-type keystore-pass trust-store
123+
trust-store-type trust-store-pass])
124+
(-> opts get-keystore-context-verifier :context))
118125
reg (-> (RegistryBuilder/create)
119126
(.register "http" (PlainGenericSocketFactory socket-factory))
120-
(.register "https" (SSLGenericSocketFactory socket-factory ssl-context))
127+
(.register "https"
128+
(SSLGenericSocketFactory
129+
socket-factory ssl-context))
121130
(.build))]
122131
(PoolingHttpClientConnectionManager. reg))))
123132

src/clj_http/core.clj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
num-redirects (count (.getRedirectLocations typed-context))]
7373
(if (<= max-redirects num-redirects)
7474
false
75-
(.isRedirected DefaultRedirectStrategy/INSTANCE request response typed-context))))))
75+
(.isRedirected DefaultRedirectStrategy/INSTANCE
76+
request response typed-context))))))
7677

7778
(defn get-redirect-strategy [redirect-strategy]
7879
(case redirect-strategy
@@ -367,8 +368,10 @@
367368
(get-conn-mgr async? req))
368369
proxy-ignore-hosts (or proxy-ignore-hosts
369370
#{"localhost" "127.0.0.1"})
370-
^RequestConfig request-config (or http-request-config (request-config req))
371-
^HttpClientContext context (http-context request-config http-client-context)
371+
^RequestConfig request-config (or http-request-config
372+
(request-config req))
373+
^HttpClientContext context (http-context
374+
request-config http-client-context)
372375
^HttpUriRequest http-req (http-request-for
373376
request-method http-url body)]
374377
(when-not (conn/reusable? conn-mgr)

src/clj_http/multipart.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"Takes a multipart vector of maps and creates a MultipartEntity with each
130130
map added as a part, depending on the type of content."
131131
[multipart]
132-
(let [mp-entity (MultipartEntity. HttpMultipartMode/STRICT
132+
(let [mp-entity (MultipartEntity. HttpMultipartMode/STRICT
133133
nil
134134
(encoding-to-charset "UTF-8"))]
135135
(doseq [m multipart]

test/clj_http/test/client_test.clj

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@
163163
(is (= 200 (:status resp)))
164164
(is (= :get (:request-method (:req resp))))
165165
(is (= :http (:scheme (:req resp))))
166-
(is (= ["http://example.com" "http://example.net/bat"] (:trace-redirects resp)))
166+
(is (= ["http://example.com" "http://example.net/bat"]
167+
(:trace-redirects resp)))
167168
(is (= "/bat" (:uri (:req resp))))))
168169

169170
(deftest redirect-on-get-async
@@ -181,7 +182,8 @@
181182
(is (= 200 (:status @resp)))
182183
(is (= :get (:request-method (:req @resp))))
183184
(is (= :http (:scheme (:req @resp))))
184-
(is (= ["http://example.com" "http://example.net/bat"] (:trace-redirects @resp)))
185+
(is (= ["http://example.com" "http://example.net/bat"]
186+
(:trace-redirects @resp)))
185187
(is (= "/bat" (:uri (:req @resp))))
186188
(is (not (realized? exception)))))
187189

@@ -198,7 +200,8 @@
198200
(is (= 200 (:status resp)))
199201
(is (= :get (:request-method (:req resp))))
200202
(is (= :http (:scheme (:req resp))))
201-
(is (= ["http://example.com" "http://example.com/bat"] (:trace-redirects resp)))
203+
(is (= ["http://example.com" "http://example.com/bat"]
204+
(:trace-redirects resp)))
202205
(is (= "/bat" (:uri (:req resp))))))
203206

204207
(deftest relative-redirect-on-get-async
@@ -216,7 +219,8 @@
216219
(is (= 200 (:status @resp)))
217220
(is (= :get (:request-method (:req @resp))))
218221
(is (= :http (:scheme (:req @resp))))
219-
(is (= ["http://example.com" "http://example.com/bat"] (:trace-redirects @resp)))
222+
(is (= ["http://example.com" "http://example.com/bat"]
223+
(:trace-redirects @resp)))
220224
(is (= "/bat" (:uri (:req @resp))))
221225
(is (not (realized? exception)))))
222226

@@ -279,7 +283,8 @@
279283
(is (= 200 (:status resp)))
280284
(is (= :get (:request-method (:req resp))))
281285
(is (= :http (:scheme (:req resp))))
282-
(is (= ["http://example.com" "http://example.net/bat?x=y"] (:trace-redirects resp)))
286+
(is (= ["http://example.com" "http://example.net/bat?x=y"]
287+
(:trace-redirects resp)))
283288
(is (= "/bat" (:uri (:req resp))))
284289
(is (= "x=y" (:query-string (:req resp))))
285290
(is (nil? (:query-params (:req resp))))))
@@ -353,7 +358,8 @@
353358
(is (= 200 (:status resp)))
354359
(is (= :get (:request-method (:req resp))))
355360
(is (= :http (:scheme (:req resp))))
356-
(is (= ["http://example.com" "http://example.net/bat"] (:trace-redirects resp)))
361+
(is (= ["http://example.com" "http://example.net/bat"]
362+
(:trace-redirects resp)))
357363
(is (= "/bat" (:uri (:req resp)))))))
358364

359365
(deftest redirect-303-to-get-on-any-method-async
@@ -373,7 +379,8 @@
373379
(is (= 200 (:status @resp)))
374380
(is (= :get (:request-method (:req @resp))))
375381
(is (= :http (:scheme (:req @resp))))
376-
(is (= ["http://example.com" "http://example.net/bat"] (:trace-redirects @resp)))
382+
(is (= ["http://example.com" "http://example.net/bat"]
383+
(:trace-redirects @resp)))
377384
(is (= "/bat" (:uri (:req @resp))))
378385
(is (not (realized? exception))))))
379386

@@ -441,7 +448,8 @@
441448
:request-method method
442449
:force-redirects true})]
443450
(is (= 200 (:status resp)))
444-
(is (= ["http://example.com" "http://example.com/bat"] (:trace-redirects resp)))
451+
(is (= ["http://example.com" "http://example.com/bat"]
452+
(:trace-redirects resp)))
445453
(is (= "ok" (:body resp)))
446454
(is (= expected-method (:request-method (:req resp)))))))
447455

@@ -454,15 +462,17 @@
454462
:trace-redirects trace-redirects
455463
:req req}
456464
{:status status :body body :req req
457-
:headers {"location" "http://example.com/bat"}})))
465+
:headers {"location"
466+
"http://example.com/bat"}})))
458467
r-client (client/wrap-redirects client)
459468
resp (promise)
460469
exception (promise)
461470
_ (r-client {:body "ok" :url "http://example.com"
462471
:request-method method
463472
:force-redirects true} resp exception)]
464473
(is (= 200 (:status @resp)))
465-
(is (= ["http://example.com" "http://example.com/bat"] (:trace-redirects @resp)))
474+
(is (= ["http://example.com" "http://example.com/bat"]
475+
(:trace-redirects @resp)))
466476
(is (= "ok" (:body @resp)))
467477
(is (= expected-method (:request-method (:req @resp))))
468478
(is (not (realized? exception))))))

test/clj_http/test/conn_mgr_test.clj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
TrustStrategy)
1313
(org.apache.http.conn.socket PlainConnectionSocketFactory)
1414
(org.apache.http.nio.conn NoopIOSessionStrategy)
15-
(org.apache.http.nio.conn.ssl SSLIOSessionStrategy)
16-
))
15+
(org.apache.http.nio.conn.ssl SSLIOSessionStrategy)))
1716

1817
(def client-ks "test-resources/client-keystore")
1918
(def client-ks-pass "keykey")
@@ -50,18 +49,18 @@
5049
plain-socket-factory (.lookup sr "http")
5150
ssl-socket-factory (.lookup sr "https")]
5251
(is (instance? PlainConnectionSocketFactory plain-socket-factory))
53-
(is (instance? SSLConnectionSocketFactory ssl-socket-factory))
54-
))
52+
(is (instance? SSLConnectionSocketFactory ssl-socket-factory))))
5553

5654
(deftest keystore-session-strategy
5755
(let [strategy-registry (conn-mgr/get-keystore-strategy-registry
58-
{:keystore client-ks :keystore-pass client-ks-pass
59-
:trust-store client-ks :trust-store-pass client-ks-pass})
56+
{:keystore client-ks
57+
:keystore-pass client-ks-pass
58+
:trust-store client-ks
59+
:trust-store-pass client-ks-pass})
6060
noop-session-strategy (.lookup strategy-registry "http")
6161
ssl-session-strategy (.lookup strategy-registry "https")]
6262
(is (instance? NoopIOSessionStrategy noop-session-strategy))
63-
(is (instance? SSLIOSessionStrategy ssl-session-strategy))
64-
))
63+
(is (instance? SSLIOSessionStrategy ssl-session-strategy))))
6564

6665
(deftest ^:integration ssl-client-cert-get
6766
(let [server (ring/run-jetty secure-handler
@@ -93,9 +92,9 @@
9392
(let [resp (promise)
9493
exception (promise)
9594
_ (core/request {:request-method :get :uri "/get"
96-
:server-port 18084 :scheme :https
97-
:insecure? true :server-name "localhost"
98-
:async? true} resp exception)]
95+
:server-port 18084 :scheme :https
96+
:insecure? true :server-name "localhost"
97+
:async? true} resp exception)]
9998
(is (= 403 (:status (deref resp 1000 {:status :timeout})))))
10099
(let [resp (promise)
101100
exception (promise)

test/clj_http/test/core_test.clj

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@
304304
:allow-circular-redirects true})]
305305
(is (= 302 (:status resp)))
306306
(is (= 3 (count (:trace-redirects resp))))
307-
(is (= ["http://localhost:18080/redirect" "http://localhost:18080/redirect" "http://localhost:18080/redirect"]
307+
(is (= ["http://localhost:18080/redirect"
308+
"http://localhost:18080/redirect"
309+
"http://localhost:18080/redirect"]
308310
(:trace-redirects resp))))
309311

310312
(is (thrown-with-msg? Exception #"Maximum redirects \(2\) exceeded"
@@ -346,14 +348,17 @@
346348
(let [transit-json-resp (client/get (localhost "/transit-json") {:as :auto})
347349
transit-msgpack-resp (client/get (localhost "/transit-msgpack")
348350
{:as :auto})
349-
bad-status-resp-default (client/get (localhost "/transit-json-bad")
350-
{:throw-exceptions false :as :transit+json})
351-
bad-status-resp-always (client/get (localhost "/transit-json-bad")
352-
{:throw-exceptions false :as :transit+json
353-
:coerce :always})
354-
bad-status-resp-exceptional (client/get (localhost "/transit-json-bad")
355-
{:throw-exceptions false :as :transit+json
356-
:coerce :exceptional})
351+
bad-status-resp-default
352+
(client/get (localhost "/transit-json-bad")
353+
{:throw-exceptions false :as :transit+json})
354+
bad-status-resp-always
355+
(client/get (localhost "/transit-json-bad")
356+
{:throw-exceptions false :as :transit+json
357+
:coerce :always})
358+
bad-status-resp-exceptional
359+
(client/get (localhost "/transit-json-bad")
360+
{:throw-exceptions false :as :transit+json
361+
:coerce :exceptional})
357362
empty-resp (client/get (localhost "/transit-json-empty")
358363
{:throw-exceptions false :as :transit+json})]
359364
(is (= 200
@@ -369,7 +374,7 @@
369374
(:body transit-msgpack-resp)))
370375

371376
(is (nil? (:body empty-resp)))
372-
377+
373378
(is (= "[\"^ \", \"~:foo\",\"bar\"]"
374379
(:body bad-status-resp-default)))
375380
(is (= {:foo "bar"}
@@ -642,16 +647,18 @@
642647
real-http-client core/http-client
643648
http-context (HttpClientContext/create)
644649
request-config (.build (RequestConfig/custom))]
645-
(with-redefs [core/http-client (fn [& args]
646-
(proxy [org.apache.http.impl.client.CloseableHttpClient] []
647-
(execute [http-req context]
648-
(swap! called-args conj [http-req context])
649-
(.execute (apply real-http-client args) http-req context))))]
650+
(with-redefs
651+
[core/http-client
652+
(fn [& args]
653+
(proxy [org.apache.http.impl.client.CloseableHttpClient] []
654+
(execute [http-req context]
655+
(swap! called-args conj [http-req context])
656+
(.execute (apply real-http-client args) http-req context))))]
650657
(client/request {:method :get
651658
:url "http://localhost:18080/get"
652659
:http-client-context http-context
653660
:http-request-config request-config})
654661

655662
(let [context-for-request (last (last @called-args))]
656-
(is (= http-context context-for-request))
657-
(is (= request-config (.getRequestConfig context-for-request)))))))
663+
(is (= http-context context-for-request))
664+
(is (= request-config (.getRequestConfig context-for-request)))))))

0 commit comments

Comments
 (0)