File: README.org

package info (click to toggle)
clj-http-clojure 3.12.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 600 kB
  • sloc: makefile: 16
file content (1614 lines) | stat: -rw-r--r-- 64,876 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
#+TITLE:    clj-http documentation
#+AUTHOR:   Lee Hinman
#+STARTUP:  align fold nodlcheck lognotestate showall
#+OPTIONS:  H:4 num:nil toc:t \n:nil @:t ::t |:t ^:{} -:t f:t *:t
#+OPTIONS:  skip:nil d:(HIDE) tags:not-in-toc auto-id:t
#+PROPERTY: header-args :results code :exports both :noweb yes
#+HTML_HEAD: <style type="text/css"> body {margin-right:15%; margin-left:15%;} </style>
#+LANGUAGE: en

[[https://clojars.org/clj-http][file:https://img.shields.io/clojars/v/clj-http.svg]] [[https://github.com/dakrone/clj-http/actions?query=workflow%3A%22Clojure+CI%22][file:https://github.com/dakrone/clj-http/workflows/Clojure%20CI/badge.svg]] [[https://gitter.im/clj-http/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge][file:https://badges.gitter.im/clj-http/Lobby.svg]]

* Table of Contents                                                     :TOC_3:
:PROPERTIES:
:CUSTOM_ID: h-aaf075ea-2f0e-4a45-871a-0f89c838fb4b
:END:
- [[#branches][Branches]]
- [[#introduction][Introduction]]
  - [[#overview][Overview]]
  - [[#philosophy][Philosophy]]
- [[#installation][Installation]]
- [[#quickstart][Quickstart]]
  - [[#head][HEAD]]
  - [[#get][GET]]
  - [[#put][PUT]]
  - [[#post][POST]]
  - [[#delete][DELETE]]
  - [[#async-http-request][Async HTTP Request]]
    - [[#cancelling-requests][Cancelling Requests]]
  - [[#coercions][Coercions]]
    - [[#input-coercion][Input coercion]]
    - [[#output-coercion][Output coercion]]
  - [[#headers][Headers]]
  - [[#query-string-parameters][Query-string parameters]]
  - [[#meta-tag-headers][Meta Tag Headers]]
  - [[#link-headers][Link Headers]]
  - [[#redirects][Redirects]]
    - [[#how-to-create-a-custom-redirectstrategy][How to create a custom RedirectStrategy]]
  - [[#cookies][Cookies]]
    - [[#cookiestores][Cookiestores]]
    - [[#keystores-trust-stores][Keystores, Trust-stores]]
  - [[#exceptions][Exceptions]]
  - [[#decompression][Decompression]]
  - [[#debugging][Debugging]]
    - [[#logging][Logging]]
- [[#caching][Caching]]
- [[#authentication][Authentication]]
  - [[#basic-auth][Basic Auth]]
  - [[#digest-auth][Digest Auth]]
  - [[#ntlm-auth][NTLM Auth]]
  - [[#oauth2][oAuth2]]
- [[#advanced-usage][Advanced Usage]]
  - [[#raw-request][Raw Request]]
    - [[#boolean-options][Boolean options]]
  - [[#persistent-connections][Persistent Connections]]
  - [[#re-using-httpclient-between-requests][Re-using =HttpClient= between requests]]
  - [[#proxies][Proxies]]
  - [[#custom-middleware][Custom Middleware]]
  - [[#modifying-apache-specific-features-of-the-httpclientbuilder-and-httpasyncclientbuilder][Modifying Apache-specific features of the =HttpClientBuilder= and =HttpAsyncClientBuilder=]]
  - [[#incrementally-json-parsing][Incrementally JSON Parsing]]
  - [[#dns-resolution][DNS Resolution]]
- [[#development][Development]]
  - [[#faking-responses][Faking Responses]]
  - [[#optional-dependencies][Optional Dependencies]]
  - [[#clj-http-lite][clj-http-lite]]
  - [[#troubleshooting][Troubleshooting]]
    - [[#verifyerror-class-orgcodehausjacksonsmilesmileparser-overrides-final-method-getbinaryvalue][VerifyError class org.codehaus.jackson.smile.SmileParser overrides final method getBinaryValue...]]
    - [[#nohttpresponseexception--due-to-stale-connections][NoHttpResponseException ... due to stale connections**]]
- [[#tests][Tests]]
- [[#testimonials][Testimonials]]
- [[#other-libraries-providing-middleware][Other Libraries Providing Middleware]]
- [[#license][License]]

* Branches
:PROPERTIES:
:CUSTOM_ID: h-e390585c-cbd8-4e94-b36b-4e9c27c16720
:END:

There are branches for the major version numbers:

- 2.x (no longer maintained except for security issues)
- 3.x (current stable releases and the main Github branch)
- master (which is 4.x, unreleased, based on version 5 of the apache http client)

* Introduction
:PROPERTIES:
:CUSTOM_ID: h-d893078a-b20b-4086-9272-3d9c28c86846
:END:

** Overview
:PROPERTIES:
:CUSTOM_ID: h-d8b17d06-124e-44fd-9c86-0399f39b0254
:END:

clj-http is an HTTP library wrapping the [[http://hc.apache.org/][Apache HttpComponents]] client. This
library has taken over from mmcgrana's clj-http.

** Philosophy
:PROPERTIES:
:CUSTOM_ID: h-aa21d07d-333b-4ff2-93a9-ffdca31d8949
:END:

The design of =clj-http= is inspired by the [[https://github.com/ring-clojure/ring][Ring]] protocol for Clojure HTTP
 server applications.

The client in =clj-http.core= makes HTTP requests according to a given Ring
request map and returns [[https://github.com/ring-clojure/ring/blob/master/SPEC][Ring response maps]] corresponding to the resulting HTTP
response. The function =clj-http.client/request= uses Ring-style middleware to
layer functionality over the core HTTP request/response implementation. Methods
like =clj-http.client/get= are sugar over this =clj-http.client/request=
function.

* Installation
:PROPERTIES:
:CUSTOM_ID: h-ddfce0e2-6797-4774-add5-d5cf5bfaaa17
:END:

=clj-http= is available as a Maven artifact from [[http://clojars.org/clj-http][Clojars]].

With Leiningen/Boot:

#+BEGIN_SRC clojure
[clj-http "3.12.3"]
#+END_SRC

If you need an older version, a 2.x release is also available.

#+BEGIN_SRC clojure
[clj-http "2.3.0"]
#+END_SRC

clj-http 3.x supports clojure 1.6.0 and higher.
clj-http 4.x will support clojure 1.7.0 and higher.

* Quickstart
:PROPERTIES:
:CUSTOM_ID: h-65f0132e-1f96-4711-a84e-973817f37dd3
:END:

The main HTTP client functionality is provided by the =clj-http.client= namespace.

First, require it in the REPL:

#+BEGIN_SRC clojure
(require '[clj-http.client :as client])
#+END_SRC

Or in your application:

#+BEGIN_SRC clojure
(ns my-app.core
  (:require [clj-http.client :as client]))
#+END_SRC

The client supports simple =get=, =head=, =put=, =post=, =delete=, =copy=,
=move=, =patch=, and =options= requests. Response are returned as [[https://github.com/ring-clojure/ring/blob/master/SPEC][Ring-style
response maps]]:

** HEAD
:PROPERTIES:
:CUSTOM_ID: h-79d1bb5f-c695-46a6-af4e-a64ca599c978
:END:

#+BEGIN_SRC clojure

(client/head "http://example.com/resource")

(client/head "http://example.com/resource" {:accept :json})

#+END_SRC

** GET
:PROPERTIES:
:CUSTOM_ID: h-89c164fb-85c2-4953-a8c4-a50867adf42a
:END:

Example requests:

#+BEGIN_SRC clojure

(client/get "http://example.com/resources/id")

;; Setting options
(client/get "http://example.com/resources/3" {:accept :json})
(client/get "http://example.com/resources/3" {:accept :json :query-params {"q" "foo, bar"}})

;; Specifying headers as either a string or collection:
(client/get "http://example.com"
            {:headers {"foo" ["bar" "baz"], "eggplant" "quux"}})

;; Using either string or keyword header names:
(client/get "http://example.com"
            {:headers {:foo ["bar" "baz"], :eggplant "quux"}})

;; Completely ignore cookies:
(client/post "http://example.com" {:cookie-policy :none})
;; There are also multiple ways to handle cookies
(client/post "http://example.com" {:cookie-policy :default})
(client/post "http://example.com" {:cookie-policy :netscape})
(client/post "http://example.com" {:cookie-policy :standard})
(client/post "http://example.com" {:cookie-policy :standard-strict})

;; Cookies can be completely configurable with a custom spec by adding a
;; function to return a cookie spec for parsing the cookie. For example, if you
;; wanted to configure a spec provider to have a certain compatibility level:
(client/post "http://example.com"
             {:cookie-spec
              (fn [http-context]
                (println "generating a new cookie spec")
                (.create
                 (org.apache.http.impl.cookie.RFC6265CookieSpecProvider.
                  org.apache.http.impl.cookie.RFC6265CookieSpecProvider$CompatibilityLevel/IE_MEDIUM_SECURITY
                  (PublicSuffixMatcherLoader/getDefault))
                 http-context))})
;; Or a version with relaxed compatibility
(client/post "http://example.com"
             {:cookie-spec
              (fn [http-context]
                (println "generating a new cookie spec")
                (.create
                 (org.apache.http.impl.cookie.RFC6265CookieSpecProvider.
                  org.apache.http.impl.cookie.RFC6265CookieSpecProvider$CompatibilityLevel/RELAXED
                  (PublicSuffixMatcherLoader/getDefault))
                 http-context))})

;; Sometimes you want to do your own validation or something, which you can do
;; by proxying the CookieSpecBase. Note that this doesn't actually return the
;; cookies, because clj-http does its own cookie parsing. If you want to store
;; the cookies from these methods you'll need to use a cookie store or put it in
;; some datastructure yourself.
(client/post "http://example.com"
             {:cookie-spec
              (fn [http-context]
                (proxy [org.apache.http.impl.cookie.CookieSpecBase] []
                  ;; Version and version header
                  (getVersion [] 0)
                  (getVersionHeader [] nil)
                  ;; parse headers into cookie objects
                  (parse [header cookie-origin] (java.util.ArrayList.))
                  ;; Validate a cookie, throwing MalformedCookieException if the
                  ;; cookies isn't valid
                  (validate [cookie cookie-origin]
                    (println "validating:" cookie))
                  ;; Determine if a cookie matches the target location
                  (match [cookie cookie-origin] true)
                  ;; Format a list of cookies into a list of headers
                  (formatCookies [cookies] (java.util.ArrayList.))))})

;; If you have created your own registry for cookie policies, you can provide
;; :cookie-policy-registry to use it. See
;; clj-http.core/create-custom-cookie-policy-registry for an example of a custom
;; registry
(client/post "http://example.com"
             {:cookie-policy-registry my-custom-policy-registry
              :cookie-policy "my-policy"})

;; Need to contact a server with an untrusted SSL cert?
(client/get "https://alioth.debian.org" {:insecure? true})

;; If you don't want to follow-redirects automatically:
(client/get "http://example.com/redirects-somewhere" {:redirect-strategy :none})

;; Only follow a certain number of redirects:
(client/get "http://example.com/redirects-somewhere" {:max-redirects 5})

;; Avoid throwing exceptions if redirected too many times:
(client/get "http://example.com/redirects-somewhere" {:max-redirects 5 :redirect-strategy :graceful})

;; Throw an exception if the get takes too long. Timeouts in milliseconds.
(client/get "http://example.com/redirects-somewhere" {:socket-timeout 1000 :connection-timeout 1000})

;; Query parameters
(client/get "http://example.com/search" {:query-params {"q" "foo, bar"}})

;; "Nested" query parameters
;; (this yields a query string of `a[e][f]=6&a[b][c]=5`)
(client/get "http://example.com/search" {:query-params {:a {:b {:c 5} :e {:f 6}}}})

;; Provide cookies — uses same schema as :cookies returned in responses
;; (see the cookie store option for easy cross-request maintenance of cookies)
(client/get "http://example.com"
            {:cookies {"ring-session" {:discard true, :path "/", :value "", :version 0}}})

;; Tell clj-http not to decode cookies from the response header
(client/get "http://example.com" {:decode-cookies false})

;; Support for IPv6!
(client/get "http://[2001:62f5:9006:e472:cabd:c8ff:fee3:8ddf]")

;; Super advanced, your own http-client-context and request-config
(client/get "http://example.com/get"
            {:http-client-context my-http-client-context
             :http-request-config my-request-config})
#+END_SRC

The client will also follow redirects on the appropriate =30*= status codes.

The client transparently accepts and decompresses the =gzip= and =deflate=
content encodings.

=:trace-redirects= will contain the chain of the redirections followed.

** PUT
:PROPERTIES:
:CUSTOM_ID: h-1582cd6e-a6e8-49c8-96e3-28eee6128c31
:END:

#+BEGIN_SRC clojure

(client/put "http://example.com/api" {:body "my PUT body"})

#+END_SRC

** POST
:PROPERTIES:
:CUSTOM_ID: h-32c8ca7a-0ef2-41b8-8158-20b0e2945e5d
:END:

#+BEGIN_SRC clojure

;; Various options:
(client/post "http://example.com/api"
             {:basic-auth ["user" "pass"]
              :body "{\"json\": \"input\"}"
              :headers {"X-Api-Version" "2"}
              :content-type :json
              :socket-timeout 1000      ;; in milliseconds
              :connection-timeout 1000  ;; in milliseconds
              :accept :json})

;; Send form params as a urlencoded body (POST or PUT)
(client/post "http://example.com" {:form-params {:foo "bar"}})

;; Send form params as a json encoded body (POST or PUT)
(client/post "http://example.com" {:form-params {:foo "bar"} :content-type :json})

;; Send form params as a json encoded body (POST or PUT) with options
(client/post "http://example.com" {:form-params {:foo "bar"}
                                   :content-type :json
                                   :json-opts {:date-format "yyyy-MM-dd"}})

;; You can also specify the encoding of form parameters
(client/post "http://example.com" {:form-params {:foo "bar"}
                                   :form-param-encoding "ISO-8859-1"})

;; Send form params as a Transit encoded JSON body (POST or PUT) with options
(client/post "http://example.com" {:form-params {:foo "bar"}
                                   :content-type :transit+json
                                   :transit-opts
                                   {:encode {:handlers {}}
                                    :decode {:handlers {}}}})

;; Send form params as a Transit encoded MessagePack body (POST or PUT) with options
(client/post "http://example.com" {:form-params {:foo "bar"}
                                   :content-type :transit+msgpack
                                   :transit-opts
                                   {:encode {:handlers {}}
                                    :decode {:handlers {}}}})

;; Multipart form uploads/posts
;; takes a vector of maps, to preserve the order of entities, :name
;; will be used as the part name unless :part-name is specified
(client/post "http://example.org" {:multipart [{:name "title" :content "My Awesome Picture"}
                                               {:name "Content/type" :content "image/jpeg"}
                                               {:name "foo.txt" :part-name "eggplant" :content "Eggplants"}
                                               {:name "file" :content (clojure.java.io/file "pic.jpg")}]
                                   ;; You can also optionally pass a :mime-subtype
                                   :mime-subtype "foo"})

;; Multipart :content values can be one of the following:
;; String, InputStream, File, a byte-array, or an instance of org.apache.http.entity.mime.content.ContentBody
;; Some Multipart bodies can also support more keys (like :encoding
;; and :mime-type), check src/clj-http/multipart.clj to see all flags

;; Apache's http client automatically retries on IOExceptions, if you
;; would like to handle these retries yourself, you can specify a
;; :retry-handler. Return true to retry, false to stop trying:
(client/post "http://example.org" {:multipart [["title" "Foo"]
                                               ["Content/type" "text/plain"]
                                               ["file" (clojure.java.io/file "/tmp/missing-file")]]
                                   :retry-handler (fn [ex try-count http-context]
                                                    (println "Got:" ex)
                                                    (if (> try-count 4) false true))})

;; to handle a file with non-ascii filename, try :multipart-charset "UTF-8" and :multipart-mode BROWSER_COMPATIBLE
;; see also: https://stackoverflow.com/questions/3393445/international-characters-in-filename-in-mutipart-formdata
(import (org.apache.http.entity.mime HttpMultipartMode))

(client/post "http://example.org" {:multipart [{:content (clojure.java.io/file "日本語.txt")}]
                                   :multipart-mode HttpMultipartMode/BROWSER_COMPATIBLE
                                   :multipart-charset "UTF-8"} )

#+END_SRC

A word about flattening nested =:query-params= and =:form-params= maps. There are essentially three
different ways to handle flattening them:

- =:ignore-nested-query-string= :: Do not handle nested query parameters specially, treat them as
     the exact text they come in as. Defaults to *false*.
- =:flatten-nested-form-params= :: Flatten nested (map within a map) =:form-params= before encoding
     it as the body. Defaults to *false*, meaning form params are encoded only
     =x-www-form-urlencoded=.
- =:flatten-nested-keys= :: An advanced way of specifying which keys having nested maps should be
     flattened. A middleware function checks the previous two options
     (=:ignore-nested-query-string= and =:flatten-nested-form-params=) and modifies this to be the
     list that will be flattened.

** DELETE
:PROPERTIES:
:CUSTOM_ID: h-c7165d6b-232a-439d-9390-8c05e6ef1e6f
:END:

#+BEGIN_SRC clojure

(client/delete "http://example.com/resource")

#+END_SRC

** Async HTTP Request
:PROPERTIES:
:CUSTOM_ID: h-0e3eb987-5b2b-4874-97ef-b834394d083d
:END:
The new async HTTP request API is a Ring-style async API.
All options for synchronous request can use in asynchronous requests.
start an async request is easy, for example:

#+BEGIN_SRC clojure
;; :async? in options map need to be true
(client/get "http://example.com"
            {:async? true}
            ;; respond callback
            (fn [response] (println "response is:" response))
            ;; raise callback
            (fn [exception] (println "exception message is: " (.getMessage exception))))
#+END_SRC

All exceptions thrown during the request will be passed to the raise callback.

*** Cancelling Requests
:PROPERTIES:
:CUSTOM_ID: cancelling-requests
:END:

Calls to the http methods with =:async true= return an Apache [[https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/concurrent/BasicFuture.html][BasicFuture]] that you can call =.get=
or =.cancel= on. See the Javadocs for =BasicFuture= [[https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/concurrent/BasicFuture.html][here]]. For instance:

#+BEGIN_SRC clojure
(import '(java.util.concurrent TimeoutException TimeUnit))

(let [future (client/get "http://example.com/slow-url"
                         {:async true :oncancel #(println "request was cancelled")}
                         #(println :got %) #(println :err %))]
  (try
    (.get future 1 TimeUnit/SECONDS)
    (catch TimeoutException e
      ;; Cancel the request, it's taken too long
      (.cancel future true))))
#+END_SRC

** Coercions
:PROPERTIES:
:CUSTOM_ID: h-8902cd95-e01e-4d9b-9dc8-5f5c8f04504b
:END:

clj-http allows coercing the body of the request either before it is sent (input coercion), or after
it's received (output coercion) from the server.

*** Input coercion
:PROPERTIES:
:CUSTOM_ID: h-bed01743-2209-473d-ae86-bd187f059e0c
:END:

#+BEGIN_SRC clojure
;; body as a byte-array
(client/post "http://example.com/resources" {:body my-byte-array})

;; body as a string
(client/post "http://example.com/resources" {:body "string"})

;; :body-encoding is optional and defaults to "UTF-8"
(client/post "http://example.com/resources"
             {:body "string" :body-encoding "UTF-8"})

;; body as a file
(client/post "http://example.com/resources"
             {:body (clojure.java.io/file "/tmp/foo") :body-encoding "UTF-8"})

;; :length is optional for passing in an InputStream; if not
;; supplied it will default to -1 to signal to HttpClient to use
;; chunked encoding
(client/post "http://example.com/resources"
             {:body (clojure.java.io/input-stream "/tmp/foo")})

(client/post "http://example.com/resources"
             {:body (clojure.java.io/input-stream "/tmp/foo") :length 1000})
#+END_SRC

*** Output coercion
:PROPERTIES:
:CUSTOM_ID: h-0c8966a6-f220-4f1e-a79e-a520fb313f9e
:END:

#+BEGIN_SRC clojure
;; The default output is a string body
(client/get "http://example.com/foo.txt")

;; Coerce as a byte-array
(client/get "http://example.com/favicon.ico" {:as :byte-array})

;; Coerce as something other than UTF-8 string
(client/get "http://example.com/string.txt" {:as "UTF-16"})

;; Coerce as json
(client/get "http://example.com/foo.json" {:as :json})
(client/get "http://example.com/foo.json" {:as :json-string-keys})

;; Coerce as Transit encoded JSON or MessagePack
(client/get "http://example.com/foo" {:as :transit+json})
(client/get "http://example.com/foo" {:as :transit+msgpack})

;; Coerce as a clojure datastructure
(client/get "http://example.com/foo.clj" {:as :clojure})

;; Coerce as x-www-form-urlencoded
(client/post "http://example.com/foo" {:as :x-www-form-urlencoded})

;; Try to automatically coerce the output based on the content-type
;; header (this is currently a BETA feature!). Currently supports
;; text, json and clojure (with automatic charset detection)
;; clojure coercion requires "application/clojure" or
;; "application/edn" in the content-type header
(client/get "http://example.com/foo.json" {:as :auto})

;; Return the body as a stream
(client/get "http://example.com/bigrequest.html" {:as :stream})
;; Note that the connection to the server will NOT be closed until the
;; stream has been read

;; Return the body as a java.io.BufferedReader
(client/get "http://example.com/bigrequest.html" {:as :reader})
;; As above, the connection will remain open until the stream has been
;; read.  The reader will attempt to respect the server-specified charset,
;; if any, defaulting to UTF-8.
#+END_SRC

Output coercion with =:as :json=, =:as :json-string-keys= or =:as :x-www-form-urlencoded=, will only work with an optional dependency, see [[#optional-dependencies][Optional Dependencies]].

By default, JSON coercion is only applied when the response's status
is considered "unexceptional". If the =:unexceptional-status= option
is provided, then its value is a function which specifies what status
codes are unexceptional. =:unexceptional-status= defaults to
=clj-http.client/unexceptional-status?=.

If you would like to change under what conditions coercion is applied,
you can send the =:coerce= option, which can be set to:

#+BEGIN_SRC clojure
:always        ;; always json decode the body
:unexceptional ;; json decode when an HTTP response is considered unexceptional
:exceptional   ;; json decode when an HTTP response is considered exceptional
#+END_SRC

The =:coerce= setting defaults to =:unexceptional=.

** Headers
:PROPERTIES:
:CUSTOM_ID: h-ef64574f-f9dc-4356-95b7-d55cc6737b44
:END:

clj-http's treatment of headers is a little more permissive than the [[https://github.com/ring-clojure/ring/blob/master/SPEC][ring spec]]
specifies.

Rather than forcing all request headers to be lowercase strings,
clj-http allows strings or keywords of any case. Keywords will be
transformed into their canonical representation, so the :content-md5
header will be sent to the server as "Content-MD5", for instance.
String keys in request headers, however, will be sent to the server
with their casing unchanged.

Response headers can be read as keywords or strings of any case. If
the server responds with a "Date" header, you could access the value
of that header as :date, "date", "Date", etc.

If for some reason you require access to the original header name that
the server specified, it is available by invoking (keys ...) on the
header map.

This special treatment of headers is implemented in the
wrap-header-map middleware, which (like any middleware) can be
disabled by using with-middleware to specify different behavior.

** Query-string parameters
:PROPERTIES:
:CUSTOM_ID: h-dd49992c-a516-4af0-9735-4f4340773361
:END:

There are four different ways that query string parameters for array values can
be generated, depending on what the resulting query string should look like,
they are:

- A repeating parameter (default)
- Array style
- Indexed array style
- Comma separated style

Here is an example of the input and output for the ~:query-params~ parameter,
controlled by the ~:multi-param-style~ option:

#+BEGIN_SRC clojure
;; default style, with :multi-param-style unset
:a [1 2 3] => "a=1&a=2&a=3"
;; with :multi-param-style :array, a repeating param with array suffix
;; (PHP-style):
:a [1 2 3] => "a[]=1&a[]=2&a[]=3"
;; with :multi-param-style :indexed, a repeating param with array suffix and
;; index (Rails-style):
:a [1 2 3] => "a[0]=1&a[1]=2&a[2]=3"
;; with :multi-param-style :comma-separated, a param with comma-separated values
:a [1 2 3] => "a=1,2,3"
#+END_SRC

** Meta Tag Headers
:PROPERTIES:
:CUSTOM_ID: h-01663a63-8bc8-45da-8a3d-341402f3f3fa
:END:

HTML 4.01 allows using the tag ~<meta http-equiv="..." />~ and HTML 5 allows
using the tag ~<meta charset="..." />~ to specify a header that should be
treated as an HTTP response header. By default, clj-http will ignore the body of
the response (other than the regular output coercion), but if you need clj-http
to parse the headers out of the body, you can use the =:decode-body-headers=
option:

#+BEGIN_SRC clojure
;; without decoding body headers (defaults to off):
(:headers (client/get "http://www.yomiuri.co.jp/"))
=> {"server" "Apache",
    "content-encoding" "gzip",
    "content-type" "text/html",
    "date" "Tue, 09 Oct 2012 18:02:41 GMT",
    "cache-control" "max-age=0, no-cache",
    "expires" "Tue, 09 Oct 2012 18:02:41 GMT",
    "etag" "\"1dfb-2686-4cba2686fb8b1\"",
    "pragma" "no-cache",
    "connection" "close"}

;; with decoding body headers, notice the content-type,
;; content-style-type and content-script-type headers:
(:headers (client/get "http://www.yomiuri.co.jp/" {:decode-body-headers true}))
=> {"server" "Apache",
    "content-encoding" "gzip",
    "content-script-type" "text/javascript",
    "content-style-type" "text/css",
    "content-type" "text/html; charset=Shift_JIS",
    "date" "Tue, 09 Oct 2012 18:02:59 GMT",
    "cache-control" "max-age=0, no-cache",
    "expires" "Tue, 09 Oct 2012 18:02:59 GMT",
    "etag" "\"1dfb-2686-4cba2686fb8b1\"",
    "pragma" "no-cache",
    "connection" "close"}
#+END_SRC

This can be used to have clj-http correctly interpret the body's charset by
using:

#+BEGIN_SRC clojure
(client/get "http://www.yomiuri.co.jp/" {:decode-body-headers true :as :auto})
=> ;; correctly formatted :body (Shift_JIS charset instead of UTF-8)
#+END_SRC

Note that this feature is currently beta and uses [[https://github.com/weavejester/crouton][Crouton]] to parse the body of
the request. If you do not want to use this feature, you can include Crouton in
addition to clj-http as a dependency like so:

#+BEGIN_SRC clojure
(defproject foo "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [clj-http "0.6.0"]
                 [crouton "1.0.0"]])
#+END_SRC

Note also that HEAD requests will not return a body, in which case this setting will have no effect.

clj-http will automatically disable the =:decode-body-headers= option.

** Link Headers
:PROPERTIES:
:CUSTOM_ID: h-f7464c54-4928-474f-9132-08e6b6f3c19d
:END:

clj-http parses any [[http://tools.ietf.org/html/rfc5988][link headers]] returned in the response, and adds them to the
=:links= key on the response map. This is particularly useful for paging RESTful
APIs:

#+BEGIN_SRC clojure
(:links (client/get "https://api.github.com/gists"))
=> {:next {:href "https://api.github.com/gists?page=2"}
    :last {:href "https://api.github.com/gists?page=22884"}}
#+END_SRC

** Redirects
:PROPERTIES:
:CUSTOM_ID: h-71c966ae-f764-4bd7-801c-0f3c8413c502
:END:

clj-http conforms its behaviour regarding automatic redirects to the [[https://tools.ietf.org/html/rfc2616#section-10.3][RFC]].

It means that redirects on status =301=, =302=, =307= and =308= are not redirected on
methods other than =GET= and =HEAD=. If you want a behaviour closer to what most
browser have, you can set =:redirect-strategy= to =:lax= in your request to have
automatic redirection work on all methods by transforming the method of the
request to =GET=.

Redirect Options:

- =:trace-redirects= :: If true, clj-http will enhance the response object with a
     list of redirected URLs with key: =:trace-redirects=.
- =:redirect-strategy= :: Sets the redirect strategy for clj-http. Accepts the following:
  - =:none=     - Perform no redirects
  - =:default=  - See https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/DefaultRedirectStrategy.html
  - =:lax=      - See https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/LaxRedirectStrategy.html
  - =:graceful= - Similar to =:default=, but does not throw exceptions when max redirects is reached. This is the redirects behaviour in 2.x
  - =nil=       - When nil, assumes =:default=

You may also pass in an instance of RedirectStrategy (in the =:redirect-strategy= key) if you want a
behavior that's not implemented.

Additionally, clj-http will attempt to validate that a redirect host is not invalid, you can disable
this by setting =:validate-redirects false= in the request (the default is true)

NOTE: The options =:force-redirects= and =:follow-redirects= (present in clj-http 2.x are no longer
used). You can use =:graceful= to mostly emulate the old redirect behaviour.

*** How to create a custom RedirectStrategy
:PROPERTIES:
:CUSTOM_ID: h:a3b8b124-411f-4c4c-ac4b-777624e76bf1
:END:
As mentioned earlier, it's possible to pass a custom instance of RedirectStrategy. The snippet below shows how to create a custom =RedirectStrategy= by wrapping the default strategy.

#+begin_src clojure
  (def default-strategy org.apache.http.impl.client.DefaultRedirectStrategy/INSTANCE)

  (def logging-redirect-strategy
    (reify org.apache.http.client.RedirectStrategy
      (getRedirect [this request response context]
        (println "attempting redirect...")
        (.getRedirect default-strategy request response context))
      (isRedirected [this request response context]
        (println "checking isRedirected")
        (.isRedirected default-strategy request response context))))

  (client/get "https://httpbin.org/absolute-redirect/3" {:redirect-strategy logging-redirect-strategy})
  ;; this will output the following:
  ;;
  ;;   checking isRedirected
  ;;   attempting redirect...
  ;;   checking isRedirected
  ;;   attempting redirect...
  ;;   checking isRedirected
  ;;   attempting redirect...
  ;;   checking isRedirected
#+end_src


** Cookies
:PROPERTIES:
:CUSTOM_ID: h-3bb89b16-4be3-455e-98ec-c5ca5830ddb9
:END:

*** Cookiestores
:PROPERTIES:
:CUSTOM_ID: h-1d86fe30-f690-4c2a-9a1c-231669f4591a
:END:

clj-http can simplify the maintenance of cookies across requests if it is
provided with a _cookie store_.

#+BEGIN_SRC clojure
(binding [clj-http.core/*cookie-store* (clj-http.cookies/cookie-store)]
  (client/post "http://example.com/login" {:form-params {:username "..."
                                                         :password "..."}})
  (client/get "http://example.com/secured-page")
  ...)
#+END_SRC

(The =clj-http.cookies/cookie-store= function returns a new empty instance of a
default implementation of =org.apache.http.client.CookieStore=.)

This will allow cookies to only be _written_ to the cookie store. Cookies from
the cookie-store will not automatically be sent with future requests.

If you would like cookies from the cookie-store to automatically be sent with
each request, specify the cookie-store with the =:cookie-store= option:

#+BEGIN_SRC clojure
(let [my-cs (clj-http.cookies/cookie-store)]
  (client/post "http://example.com/login" {:form-params {:username "..."
                                                         :password "..."}
                                           :cookie-store my-cs})
  (client/post "http://example.com/update" {:body my-data
                                            :cookie-store my-cs}))
#+END_SRC

You can also use the =get-cookies= function to retrieve the cookies
from a cookie store:

#+BEGIN_SRC clojure
(def cs (clj-http.cookies/cookie-store))

(client/get "http://google.com" {:cookie-store cs})

(clojure.pprint/pprint (clj-http.cookies/get-cookies cs))
{"NID"
 {:domain ".google.com",
  :expires #<Date Tue Oct 02 10:12:06 MDT 2012>,
  :path "/",
  :value
  "58=c387....",
  :version 0},
 "PREF"
 {:domain ".google.com",
  :expires #<Date Wed Apr 02 10:12:06 MDT 2014>,
  :path "/",
  :value
  "ID=3ba...:FF=0:TM=133...:LM=133...:S=_iRM...",
  :version 0}}
#+END_SRC

*** Keystores, Trust-stores
:PROPERTIES:
:CUSTOM_ID: h-7968467a-1441-4a73-9307-9a7a5fd8e733
:END:

You can also specify your own keystore/trust-store to be used:

#+BEGIN_SRC clojure
(client/get "https://example.com" {:keystore "/path/to/keystore.ks"
                                   :keystore-type "jks" ; default: jks
                                   :keystore-pass "secretpass"
                                   :trust-store "/path/to/trust-store.ks"
                                   :trust-store-type "jks" ; default jks
                                   :trust-store-pass "trustpass"})
#+END_SRC

The =:keystore/:trust-store= values may be either paths to keystore
files or =KeyStore= instances.

** Exceptions
:PROPERTIES:
:CUSTOM_ID: h-ed9e04f1-1c7b-4c2e-9259-94d2a3e65a89
:END:

The client will throw exceptions on, well, exceptional status codes, meaning all
HTTP responses other than =#{200 201 202 203 204 205 206 207 300 301 302 303 304
307}=. clj-http will throw a [[http://github.com/scgilardi/slingshot][Slingshot]] Stone that can be caught by a regular
=(catch Exception e ...)= or in Slingshot's =try+= block:

#+BEGIN_SRC clojure
(client/get "http://example.com/broken")
=> ExceptionInfo clj-http: status 404  clj-http.client/wrap-exceptions/fn--583 (client.clj:41)
;; Or, if you would like the Exception message to contain the entire response:
(client/get "http://example.com/broken" {:throw-entire-message? true})
=> ExceptionInfo clj-http: status 404 {:status 404,
                                       :headers {"server" "nginx/1.0.4",
                                                 "x-runtime" "12ms",
                                                 "content-encoding" "gzip",
                                                 "content-type" "text/html; charset=utf-8",
                                                 "date" "Mon, 17 Oct 2011 23:15 :36 GMT",
                                                 "cache-control" "no-cache",
                                                 "status" "404 Not Found",
                                                 "transfer-encoding" "chunked",
                                                 "connection" "close"},
                                       :body "...body here..."}
   clj-http.client/wrap-exceptions/fn--584 (client.clj:42

;; You can also ignore HTTP-status-code exceptions and handle them yourself:
(client/get "http://example.com/broken" {:throw-exceptions false})
;; Or ignore an unknown host (methods return 'nil' if this is set to
;; true and the host does not exist:
(client/get "http://example.invalid" {:ignore-unknown-host? true})
;; Or customize the http statuses that will not throw:
(client/get "http://example.com/broken" {:unexceptional-status #(<= 200 % 299)})
#+END_SRC

(spacing added by me to be human readable)

How to use with Slingshot:

#+BEGIN_SRC clojure
; Response map is thrown as exception obj.
; We filter out by status codes
(try+
  (client/get "http://example.com/broken")
  (catch [:status 403] {:keys [request-time headers body]}
    (log/warn "403" request-time headers))
  (catch [:status 404] {:keys [request-time headers body]}
    (log/warn "NOT Found 404" request-time headers body))
  (catch Object _
    (log/error (:throwable &throw-context) "unexpected error")
    (throw+)))
#+END_SRC

** Decompression
:PROPERTIES:
:CUSTOM_ID: h-f780c96c-90be-4d83-9b53-227a9e5942ab
:END:

By default, clj-http will add the ={"Accept-Encoding" "gzip, deflate"}= header
to requests, and automatically decompress the resulting gzip or deflate stream
if the =Content-Encoding= header is found on the response. If this is undesired,
the ={:decompress-body false}= option can be specified:

#+BEGIN_SRC clojure
;; Auto-decompression used: (google requires a user-agent to send gzip data)
(def h {"User-Agent" "Mozilla/5.0 (Windows NT 6.1;) Gecko/20100101 Firefox/13.0.1"})
(def resp (client/get "http://google.com" {:headers h}))
(:orig-content-encoding resp)
=> "gzip" ;; <= google sent response gzipped

;; and without decompression:
(def resp2 (client/get "http://google.com" {:headers h :decompress-body false})
(:orig-content-encoding resp2)
=> nil
#+END_SRC

If clj-http decompresses something, the "content-encoding" header is removed
from the headers (because the encoding is no longer true). This allows clj-http
to be used as a pass-through proxy with ring. The original content-encoding is
available as =:orig-content-encoding= in the response map if auto-decompression
is enabled.

** Debugging
:PROPERTIES:
:CUSTOM_ID: debugging
:END:

There are four debugging methods you can use:

#+BEGIN_SRC clojure
;; print request info to *out*:
(client/get "http://example.org" {:debug true})

;; print request info to *out*, including request body:
(client/post "http://example.org" {:debug true :debug-body true :body "..."})

;; save the request that was sent in a :request key in the response:
(client/get "http://example.org" {:save-request? true})

;; save the request that was sent in a :request key in the response,
;; including the body content:
(client/get "http://example.org" {:save-request? true :debug-body true})

;; add an HttpResponseInterceptor to the request. This callback
;; is called for each redirects with the following args:
;; ^HttpResponse resp, HttpContext^ ctx
;; this allows low level debugging + access to socket.
;; see http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/HttpResponseInterceptor.html
(client/get "http://example.org" {:response-interceptor (fn [resp ctx] (println ctx))})
#+END_SRC

*** Logging
:PROPERTIES:
:CUSTOM_ID: h-0d505652-d453-48a2-a868-46aef2b8af66
:END:

Finally, if you want to access the logging that the Apache client does internally, you can set up
your dependencies to add the [[https://logging.apache.org/log4j/2.x/][log4j2]] libraries and configure the logging for clj-http. In order to do
this, you'll need to add

#+BEGIN_SRC clojure
[org.apache.logging.log4j/log4j-api "2.11.0"]
[org.apache.logging.log4j/log4j-core "2.11.0"]
[org.apache.logging.log4j/log4j-1.2-api "2.11.0"]
#+END_SRC

To your =project.clj= and have a usable log4j2.properties. I have provided one in
=resources/log4j2.properties=. Make sure to set:

#+BEGIN_SRC fundamental
rootLogger.level = debug
#+END_SRC

If you want to see debug information (or "trace" for trace logging). When you perform a request you
should see something akin to this in the logs:

#+BEGIN_SRC fundamental
[2018-03-20T20:36:34,635][DEBUG][o.a.h.c.p.RequestAddCookies] CookieSpec selected: default
[2018-03-20T20:36:34,635][DEBUG][o.a.h.c.p.RequestAuthCache] Auth cache not set in the context
[2018-03-20T20:36:34,635][DEBUG][o.a.h.i.c.BasicHttpClientConnectionManager] Get connection for route {s}->https://example.com:443
[2018-03-20T20:36:34,636][DEBUG][o.a.h.i.c.DefaultManagedHttpClientConnection] http-outgoing-1: set socket timeout to 0
[2018-03-20T20:36:34,636][DEBUG][o.a.h.i.e.MainClientExec ] Opening connection {s}->https://example.com:443
[2018-03-20T20:36:34,644][DEBUG][o.a.h.i.c.DefaultHttpClientConnectionOperator] Connecting to example.com/10.0.0.1:443
[2018-03-20T20:36:34,644][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory] Connecting socket to example.com/10.0.0.1:443 with timeout 0
[2018-03-20T20:36:34,692][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory] Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
[2018-03-20T20:36:34,693][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory] Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, ... etc ...]
[2018-03-20T20:36:34,693][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory] Starting handshake
[2018-03-20T20:36:34,841][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory] Secure session established
[2018-03-20T20:36:34,842][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory]  negotiated protocol: TLSv1.2
[2018-03-20T20:36:34,842][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory]  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
[2018-03-20T20:36:34,843][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory]  peer principal: CN=example.com
[2018-03-20T20:36:34,843][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory]  peer alternative names: [example.com, www.example.com]
[2018-03-20T20:36:34,843][DEBUG][o.a.h.c.s.SSLConnectionSocketFactory]  issuer principal: CN=Let's Encrypt Authority X3, O=Let's Encrypt, C=US
[2018-03-20T20:36:34,844][DEBUG][o.a.h.i.c.DefaultHttpClientConnectionOperator] Connection established 192.168.0.29:36792<->10.0.0.1:443
[2018-03-20T20:36:34,844][DEBUG][o.a.h.i.e.MainClientExec ] Executing request POST /post HTTP/1.1
[2018-03-20T20:36:34,844][DEBUG][o.a.h.i.e.MainClientExec ] Target auth state: UNCHALLENGED
[2018-03-20T20:36:34,844][DEBUG][o.a.h.i.e.MainClientExec ] Proxy auth state: UNCHALLENGED
[2018-03-20T20:36:34,845][DEBUG][o.a.h.headers            ] http-outgoing-1 >> POST /post HTTP/1.1
[2018-03-20T20:36:34,845][DEBUG][o.a.h.headers            ] http-outgoing-1 >> Connection: close
[2018-03-20T20:36:34,845][DEBUG][o.a.h.headers            ] http-outgoing-1 >> accept-encoding: gzip, deflate
[2018-03-20T20:36:34,845][DEBUG][o.a.h.headers            ] http-outgoing-1 >> Content-Length: 14
[2018-03-20T20:36:34,845][DEBUG][o.a.h.headers            ] http-outgoing-1 >> Content-Type: text/plain; charset=UTF-8
[2018-03-20T20:36:34,846][DEBUG][o.a.h.headers            ] http-outgoing-1 >> Host: example.com
[2018-03-20T20:36:34,846][DEBUG][o.a.h.headers            ] http-outgoing-1 >> User-Agent: Apache-HttpClient/4.5.5 (Java/9.0.1)
[2018-03-20T20:36:34,846][DEBUG][o.a.h.wire               ] http-outgoing-1 >> "POST /post HTTP/1.1[\r][\n]"
[2018-03-20T20:36:34,846][DEBUG][o.a.h.wire               ] http-outgoing-1 >> "Connection: close[\r][\n]"
[2018-03-20T20:36:34,846][DEBUG][o.a.h.wire               ] http-outgoing-1 >> "accept-encoding: gzip, deflate[\r][\n]"
[2018-03-20T20:36:34,847][DEBUG][o.a.h.wire               ] http-outgoing-1 >> "Content-Length: 14[\r][\n]"
[2018-03-20T20:36:34,847][DEBUG][o.a.h.wire               ] http-outgoing-1 >> "Content-Type: text/plain; charset=UTF-8[\r][\n]"
[2018-03-20T20:36:34,847][DEBUG][o.a.h.wire               ] http-outgoing-1 >> "Host: example.com[\r][\n]"
etc etc it will go on forever and be very verbose
#+END_SRC

This provides both the data sent and received on the wire for debugging purposes.

I've also provided an example for changing the log level from clojure in
=examples/logging-apache-requests.clj=.

* Caching
:PROPERTIES:
:CUSTOM_ID: h-2c4ee611-ca22-432e-9c33-18040566661e
:END:

clj-http supports Apache's caching client, essentially it "provides an HTTP/1.1-compliant caching
layer to be used with HttpClient--the Java equivalent of a browser cache." (see [[https://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html][the explanation in
the apache docs]]). In order to use the cache, a reusable connection manager *and* http-client must be
used.

An example of basic usage with the default options:

#+BEGIN_SRC clojure
(let [cm (conn/make-reusable-conn-manager {})
      client (:http-client (http/get "http://example.com"
                                     {:connection-manager cm :cache true}))]
  (http/get "http://example.com"
            {:connection-manager cm :http-client client :cache true})
  (http/get "http://example.com"
            {:connection-manager cm :http-client client :cache true})
  (http/get "http://example.com"
            {:connection-manager cm :http-client client :cache true}))
#+END_SRC

You can build your own cache config by providing either a map of caching configuration options, or
by providing a =CacheConfig= object, as seen below:

#+BEGIN_SRC clojure
(let [cm (conn/make-reusable-conn-manager {})
      cache-config (core/build-cache-config
                    {:cache-config {:max-object-size 4096}})
      client (:http-client (http/get "http://example.com"
                                     {:connection-manager cm :cache true}))]
  (http/get "http://example.com"
            ;; Use the default cache config settings
            {:connection-manager cm :http-client client :cache true})
  (http/get "http://example.com"
            {:connection-manager cm :http-client client :cache true
             ;; Provide cache configuration options as a map
             :cache-config {:max-object-size 9152
                            :max-cache-entries 100}})
  (http/get "http://example.com"
            {:connection-manager cm :http-client client :cache true
             ;; Provide the cache configuration as a CacheConfig object
             :cache-config cache-config}))
#+END_SRC

In the response, clj-http provides the =:cached= key to indicate whether the response was cached,
missed, etc:

- nil :: Caching was not used for this request
- =:CACHE_HIT= :: A response was generated from the cache with no requests sent upstream.
- =:CACHE_MISS= :: The response came from an upstream server.
- =:CACHE_MODULE_RESPONSE= :: The response was generated directly by the caching module.
- =:VALIDATED= :: The response was generated from the cache after validating the entry with the origin server.

* Authentication
:PROPERTIES:
:CUSTOM_ID: h-87f38469-36b4-44c6-ae74-0d8f5e80c2ed
:END:

** Basic Auth
:PROPERTIES:
:CUSTOM_ID: h-d3ea348f-88ed-4193-bb16-d8d5accdc2aa
:END:

#+BEGIN_SRC clojure

(client/get "http://example.com/protected" {:basic-auth ["user" "pass"]})
(client/get "http://example.com/protected" {:basic-auth "user:pass"})

#+END_SRC

** Digest Auth
:PROPERTIES:
:CUSTOM_ID: h-d1904589-e71e-43db-8b93-0f94ccecaabe
:END:

#+BEGIN_SRC clojure

(client/get "http://example.com/protected" {:digest-auth ["user" "pass"]})

#+END_SRC

** NTLM Auth
:PROPERTIES:
:CUSTOM_ID: h-AE80FFDC-2016-4883-9512-2BE16640339D
:END:

#+BEGIN_SRC clojure

(client/get "http://example.com/protected" {:ntlm-auth ["user" "pass" "host" "domain"]})

#+END_SRC

** oAuth2
:PROPERTIES:
:CUSTOM_ID: h-dd077440-a1de-437e-b34e-5d6d0d1da4bd
:END:

#+BEGIN_SRC clojure

(client/get "http://example.com/protected" {:oauth-token "secret-token"})

#+END_SRC

* Advanced Usage
:PROPERTIES:
:CUSTOM_ID: h-d52ca837-a575-402f-81fe-53241d85f2db
:END:

** Raw Request
:PROPERTIES:
:CUSTOM_ID: h-0d2eadbf-c1ad-4514-a932-9d173582a790
:END:

A more general =request= function is also available, which is useful as a
primitive for building higher-level interfaces:

#+BEGIN_SRC clojure
(defn api-action [method path & [opts]]
  (client/request
    (merge {:method method :url (str "http://example.com/" path)} opts)))
#+END_SRC

*** Boolean options
:PROPERTIES:
:CUSTOM_ID: h-a37c718c-43bb-43ce-936a-21ef65147295
:END:

Since 0.9.0, all boolean options can be expressed as either ={:debug true}= or
={:debug? true}=, with or without the question mark.

** Persistent Connections
:PROPERTIES:
:CUSTOM_ID: h-4e9f116d-c293-4a0c-8e11-435c440bfe97
:END:

clj-http can use persistent connections to speed up connections if multiple
connections are being used:

#+BEGIN_SRC clojure
(with-connection-pool {:timeout 5 :threads 4 :insecure? false :default-per-route 10}
  (get "http://example.org/1")
  (post "http://example.org/2")
  (get "http://example.org/3")
  ...
  (get "http://example.org/999"))
#+END_SRC

For async request, you can use =with-async-connection-pool=

#+BEGIN_SRC clojure
(with-async-connection-pool {:timeout 5 :threads 4 :insecure? false :default-per-route 10}
  (get "http://example.org/1" {:async? true} resp1 exce1)
  (post "http://example.org/2" {:async? true} resp2 exce2)
  (get "http://example.org/3" {:async? true} resp3 exce3)
  ...
  (get "http://example.org/999" {:async? true} resp999 exce999))
#+END_SRC

This is MUCH faster than sequentially performing all requests, because a
persistent connection can be used instead creating a new connection for each
request.

If you want to start an async request in the =respond= callback of an async request and
reuse the pool context, just use =reuse-pool=.

#+BEGIN_SRC clojure
(with-async-connection-pool {:timeout 5 :threads 4 :insecure? false :default-per-route 10}
  (get "http://example.org/1" {:async? true} resp1 exce1)
  (post "http://example.org/2"
        {:async? true}
        (fn [resp] (get "http://example.org/3"
                        (reuse-pool {:async? true} resp)
                        resp3 exce3))
        exce2))
#+END_SRC

There are many advanced options available when creating asynchronous connection pools that can be
configured by passing an =:io-config= map in the connection manager parameters. It supports:

- =:connect-timeout=
- =:interest-op-queued=
- =:io-thread-count=
- =:rcv-buf-size=
- =:select-interval=
- =:shutdown-grace-period=
- =:snd-buf-size=
- =:so-keep-alive=
- =:so-linger=
- =:so-timeout=
- =:tcp-no-delay=

See the docstring on =with-async-connection-pool= for more information about these options.

If you would prefer to handle managing the connection manager yourself, you can
create a connection manager and specify it for each request:

#+BEGIN_SRC clojure
(def cm (clj-http.conn-mgr/make-reusable-conn-manager {:timeout 2 :threads 3}))
(def cm2 (clj-http.conn-mgr/make-reusable-conn-manager {:timeout 10 :threads 1}))

(get "http://example.org/1" {:connection-manager cm2})
(post "http://example.org/2" {:connection-manager cm})
(get "http://example.org/3" {:connection-manager cm2})

;; Don't forget to shut it down when you're done!
(clj-http.conn-mgr/shutdown-manager cm)
(clj-http.conn-mgr/shutdown-manager cm2)
#+END_SRC

See the docstring on =make-reusable-conn-manager= for options and default
values.

In the current version, pooled async request CANNOT specify connection manager.

** Re-using =HttpClient= between requests
:PROPERTIES:
:CUSTOM_ID: h-b79b07fb-d024-49a2-a7f7-53863d1b8d6d
:END:

In some cases, you may want to re-use the same =HttpClient= object between requests, either so you
don't have to build it every time, or because you make some configuration change to the request.
clj-http will return the built HTTP client in =:http-client= which you can then specify in
subsequent requests (with =:http-client=). Note that in order to reuse the client a connection
manager must be used.

#+BEGIN_SRC clojure
;; Re-use the HttpClient clj-http builds for you:
(let [cm (conn/make-reusable-conn-manager {})
      resp (client/get "http://example.com" {:connection-manager cm})
      hclient (:http-client resp)]
  (client/get "http://example.com/1"
              {:connection-manager cm :http-client hclient})
  (client/get "http://example.com/2"
              {:connection-manager cm :http-client hclient})
  (client/get "http://example.com/3"
              {:connection-manager cm :http-client hclient}))

;; You can also build your own, using clj-http's helper or manually building it:
(let [cm (conn/make-reusable-conn-manager {})
      hclient (core/build-http-client {} false cm)]
  (client/get "http://example.com/1"
              {:connection-manager cm :http-client hclient})
  (client/get "http://example.com/2"
              {:connection-manager cm :http-client hclient})
  (client/get "http://example.com/3"
              {:connection-manager cm :http-client hclient}))

;; Async http clients may also be created and re-used:
(let [acm (conn/make-reuseable-async-conn-manager {})
      ahclient (core/build-async-http-client {} acm)]
  (client/get "http://example.com/1"
              {:connection-manager cm :http-client ahclient}
              handle-response handle-failure)
  (client/get "http://example.com/2"
              {:connection-manager cm :http-client ahclient}
              handle-response handle-failure)
  (client/get "http://example.com/3"
              {:connection-manager cm :http-client ahclient}
              handle-response handle-failure))
#+END_SRC

** Proxies
:PROPERTIES:
:CUSTOM_ID: h-49f9ca81-0bad-4cd8-87ac-c09a85fa5500
:END:

A proxy can be specified by setting the Java properties: =<scheme>.proxyHost=
and =<scheme>.proxyPort= where =<scheme>= is the client scheme used (normally
'http' or 'https'). =http.nonProxyHosts= allows you to specify a pattern for
hostnames which do not require proxy routing - this is shared for all schemes.
Additionally, per-request proxies can be specified with the =proxy-host= and
=proxy-port= options (this overrides =http.nonProxyHosts= too):

#+BEGIN_SRC clojure
(client/get "http://example.com" {:proxy-host "127.0.0.1" :proxy-port 8118})
#+END_SRC

You can also specify the =proxy-ignore-hosts= parameter with a list of
hosts where the proxy should be ignored. By default this list is
=#{"localhost" "127.0.0.1"}=.

A SOCKS proxy can be used by creating a proxied connection manager with
=clj-http.conn-mgr/make-socks-proxied-conn-manager=. Then using that connection
manager in the request.

For example if you wanted to connect to a local socks proxy on port =8081= you
would:

#+BEGIN_SRC clojure
(ns foo.bar
  (:require [clj-http.client :as client]
            [clj-http.conn-mgr :as conn-mgr]))

(client/get "https://google.com"
            {:connection-manager
             (conn-mgr/make-socks-proxied-conn-manager "localhost" 8081)})
#+END_SRC

If your SOCKS connection requires a keystore / trust-store, you can specify that too:

#+BEGIN_SRC clojure
(ns foo.bar
  (:require [clj-http.client :as client]
            [clj-http.conn-mgr :as conn-mgr]))

(client/get "https://google.com"
            {:connection-manager
             (conn-mgr/make-socks-proxied-conn-manager "localhost" 8081
               {:keystore "/path/to/keystore.ks"
                :keystore-type "jks" ; default: jks
                :keystore-pass "secretpass"
                :trust-store "/path/to/trust-store.ks"
                :trust-store-type "jks" ; default jks
                :trust-store-pass "trustpass"})})
#+END_SRC

You can also store the proxied connection manager and reuse it later.

** Custom Middleware
:PROPERTIES:
:CUSTOM_ID: h-c51cba6c-5c1b-4941-93c3-f769bb533562
:END:

Sometime it is desirable to run a request with some middleware enabled and some
left out, the =with-middleware= method provides this functionality:

#+BEGIN_SRC clojure
(with-middleware [#'clj-http.client/wrap-method
                  #'clj-http.client/wrap-url
                  #'clj-http.client/wrap-exceptions]
  (get "http://example.com")
  (post "http://example.com/foo" {:body (.getBytes "foo")}))
#+END_SRC

To see available middleware, check the =clj-http.client/default-middleware= var,
which is a vector of the default middleware that clj-http uses.
=clj-http.client/*current-middleware*= is bound to the current list of
middleware during request time.

** Modifying Apache-specific features of the =HttpClientBuilder= and =HttpAsyncClientBuilder=
:PROPERTIES:
:CUSTOM_ID: h:844f078c-531e-445e-b7ce-76092bcc9928
:END:

While clj-http tries to provide the features needed, there are times when it does not provide access
to a parameter that you need. In these cases, you can use a couple of advanced parameters to provide
arbitrary configuration functions to be run on the =HttpClientBuilder= by specifying
=:http-builder-fns= and =:async-http-builder-fns=.

Each of these variables is a sequence of functions of two arguments, the http builder
(=HttpClientBuilder= for =:http-builder-fns= and =HttpAsyncClientBuilder= for
=:async-http-builder-fns=) and the request map.

#+BEGIN_SRC clojure
;; A function that takes a builder and disables Apache's cookie management
(defun my-cookie-disabler [^HttpClientBuilder builder
                           request]
  (when (:disable-cookies request)
    (.disableCookieManagement builder)))

;; The functions to modify the builder are passed in
(http/post "http://www.example.org" {:http-builder-fns [my-cookie-disabler]
                                     :disable-cookies true})
#+END_SRC

The functions are run in the order they are passed in (inside a =doseq=).

By specifying =:http-client-builder=, your own instance of
=HttpClientBuilder= will be used. A supplied =HttpClientBuilder= which
sets the connection manager, redirect strategy, retry handler, route
planner, cache, or cookie spec registry may find these overridden by
clj-http's =:connection-manager=, =:redirect-strategy=,
=:retry-handler=, =:cache=, or =:cookie-policy-registry= or
=:cookie-spec=, respectively.

** Incrementally JSON Parsing
:PROPERTIES:
:CUSTOM_ID: h:b01c16e8-7179-468e-8890-316939ec0e38
:END:
[[https://github.com/dakrone/cheshire][cheshire]] supports incrementally parsing JSON using lazy sequences. This approach can useful for
processing large top-level JSON arrays because it doesn't require upfront work consuming the entire stream.

#+begin_src clojure
  (require '[cheshire.core :as json])

  (defn print-all-pokemon-names [pokemons]
    (for [pokemon pokemons]
      (println (get-in pokemon [:name :english]))))

  (let [url "https://raw.githubusercontent.com/fanzeyi/pokemon.json/master/pokedex.json"
        response (get url {:as :reader})]
    (with-open [reader (:body response)]  ; closes the underlying connection when we're done
      (let [pokemons (json/parse-stream reader true)]
        ; You must perform all reads from the stream inside `with-open`,
        ; any , any lazy
        (doall (print-all-pokemon-names pokemons)))))
#+end_src

Keep in mind that the =reader= object wraps a HTTP connection. The user needs to be aware of two
things:

1. The user should close the reader after processing the stream, otherwise the underlying HTTP
   Connection may leak and create subtle bugs. Clojure's [[https://clojuredocs.org/clojure.core/with-open][with-open]] is useful here.

2. You should realize any lazy sequences before closing the connection. Use [[https://clojuredocs.org/clojure.core/doall][doall]] or [[https://clojure.org/reference/transducers][transducers]] to
   prevent bugs from lazy IO. See [[https://stuartsierra.com/2015/08/25/clojure-donts-lazy-effects][Clojure Don'ts: Lazy Effects]].

In previous versions of =clj-http= (<= 3.10.0), =clj-http= defaulted to lazily parsing JSON, but this
was slow and also confused users who didn't expect laziness.

** DNS Resolution

Users may add their own DNS resolver function to override the default DNS Resolver. This is useful in situations where you are unable to change the name to IP Address mapping. It is analogous to the =--resolve= flag present in =curl=. This example uses =org.apache.http.impl.conn.InMemoryDnsResolver= to resolve =example.com= to IP Address =127.0.0.1=. 

#+BEGIN_SRC clojure
(client/get "https://example.com" {:dns-resolver (doto (InMemoryDnsResolver.)
                                                   (.add "example.com" (into-array[(InetAddress/getByAddress (byte-array [127 0 0 1]))])))})
#+END_SRC

This option is supported for all of the connection managers.

The =dns-resolver= can be any instance of =DnsResolver=. Here is an example of a custom implementation that attempts to look up the hostname in the supplied map and falls back to the default SystemDnsResolver if not found. Note how IPV6 addresses are specified.

#+BEGIN_SRC clojure
(defn custom-dns-resolver
  [host-map]
  (let [system-dns-resolver (org.apache.http.impl.conn.SystemDefaultDnsResolver.)]
    (reify
      org.apache.http.conn.DnsResolver
      (^"[Ljava.net.InetAddress;" resolve [this ^String host]
       (if-let [address (get host-map host)]
         (into-array [(java.net.InetAddress/getByAddress host (byte-array address))])
         (.resolve system-dns-resolver host))))))
       
(client/get "https://example.com" {:dns-resolver (custom-dns-resolver {"example.com" [127 0 0 1]
                                                                        "www.google.com" [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]})})
#+END_SRC
       

* Development
:PROPERTIES:
:CUSTOM_ID: h-65bbf017-2e8b-4c43-824b-24b89cc27a70
:END:

Please send a pull request or open an issue if you have any problems. See =CONTRIBUTING.md= for more
information.

** Faking Responses
:PROPERTIES:
:CUSTOM_ID: h-c3d9c7e0-cc3f-47bf-91e3-b12567b08eb6
:END:

If you need to fake clj-http responses (for things like testing and such), check
out the [[https://github.com/myfreeweb/clj-http-fake][clj-http-fake]] library.

** Optional Dependencies
:PROPERTIES:
:CUSTOM_ID: h-f1fbdad3-cf40-41e0-8ae0-8716419be228
:END:

In 2.0.0+ clj-http's optional dependencies at excluded by default, in order to
use the features you will need to add them to your =project.clj= file.

clj-http currently has four optional dependencies, =cheshire=, =crouton=,
=tools.reader= and =ring/ring-codec=. Any number of them may be included by
adding them with the clj-http dependency in your project.clj:

#+BEGIN_SRC clojure
;; optional dependencies
[cheshire] ;; for :as :json
[crouton] ;; for :decode-body-headers
[org.clojure/tools.reader] ;; for :as :clojure
[ring/ring-codec] ;; for :as :x-www-form-urlencoded
#+END_SRC

Prior to 2.0.0, you can /exclude/ the dependencies and clj-http will work
without them.

** clj-http-lite
:PROPERTIES:
:CUSTOM_ID: h-ba6b263b-74a5-40f3-afc1-b0d785554c2b
:END:

Like clj-http but need something more lightweight without as many external
dependencies? Check out [[https://github.com/hiredman/clj-http-lite][clj-http-lite]] for a project that can be used as a
drop-in replacement for clj-http.

** Troubleshooting
:PROPERTIES:
:CUSTOM_ID: h-c543201e-a0e5-4e84-8eb2-6bf3e21a3140
:END:
*** VerifyError class org.codehaus.jackson.smile.SmileParser overrides final method getBinaryValue...
:PROPERTIES:
:CUSTOM_ID: h-c3a8ebc3-a247-4327-8b71-0097d1380873
:END:

This is actually caused by your project attempting to use [[https://github.com/mmcgrana/clj-json/][clj-json]] and [[https://github.com/dakrone/cheshire][cheshire]]
in the same classloader. You can fix the issue by either not using clj-json (and
thus choosing cheshire), or specifying an exclusion for clj-http in your project
like this:

#+BEGIN_SRC clojure
(defproject foo "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [clj-http "0.3.4" :exclusions [cheshire]]])
#+END_SRC

Note that if you exclude cheshire, json decoding of response bodies
and json encoding of form-params cannot happen, you are responsible
for your own encoding/decoding.

As of clj-http 0.3.5, you should no longer see this, as Cheshire 3.1.0
and clj-json can now live together without causing problems.

*** NoHttpResponseException ... due to stale connections**
:PROPERTIES:
:CUSTOM_ID: h-9d7cf050-ed5b-4d23-8b02-97a9b9c94737
:END:

Persistent connections kept alive by the connection manager become stale: the
target server shuts down the connection on its end without HttpClient being able
to react to that event, while the connection is being idle, thus rendering the
connection half-closed or 'stale'.

This can be solved by using (with-connection-pool) as described in the
'Using Persistent Connection' section above.

* Tests
:PROPERTIES:
:CUSTOM_ID: h-a52feb3d-d966-4287-a07e-ad7aa7918fd5
:END:

To run the tests:

#+BEGIN_SRC
$ lein deps
$ lein test

Run all tests (including integration):
$ lein test :all

Run tests against all clojure versions
$ lein all test
$ lein all test :all
#+END_SRC

* Testimonials
:PROPERTIES:
:CUSTOM_ID: h-3044d1f7-6772-43c2-9ded-8c71c7f9ada2
:END:

With over [[https://clojars.org/clj-http][three million]] downloads, clj-http is a widely used, battle-tested clojure library. It is
also included in other libraries (like database clients) as a low-level http wrapper.

Libraries using clj-http:

- [[https://github.com/mattrepl/clj-oauth][clj-oauth]]
- [[https://github.com/clojurewerkz/elastisch][elasticsearch]]
- [[https://github.com/olauzon/capacitor][influxdb]]

Libraries inspired by clj-http:

- [[https://github.com/mpenet/jet][jet]]
- [[https://github.com/hiredman/clj-http-lite][clj-http-lite]]

* Other Libraries Providing Middleware
:PROPERTIES:
:CUSTOM_ID: other-middleware
:END:

- [[https://github.com/sharetribe/aws-sig4][aws-sig4]] :: a pure clojure implementation of AWS v4 signature request signing as middleware

(feel free to open a PR or issue if you'd like to add middleware here)

* License
:PROPERTIES:
:CUSTOM_ID: h-2de3db75-7a1b-42b8-ad3b-6ef27fc2a5ea
:END:

Released under the MIT License:
<http://www.opensource.org/licenses/mit-license.php>

# Local Variables:
# fill-column: 100
# End: