This file is indexed.

/usr/share/doc/libghc-servant-server-doc/html/servant-server.txt is in libghc-servant-server-doc 0.8.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A family of combinators for defining webservices APIs and serving them
--   
--   A family of combinators for defining webservices APIs and serving them
--   
--   You can learn about the basics in the <a>tutorial</a>.
--   
--   <a>Here</a> is a runnable example, with comments, that defines a dummy
--   API and implements a webserver that serves this API, using this
--   package.
--   
--   <a>CHANGELOG</a>
@package servant-server
@version 0.8.1

module Servant.Server.Internal.Context

-- | <a>Context</a>s are used to pass values to combinators. (They are
--   <b>not</b> meant to be used to pass parameters to your handlers, i.e.
--   they should not replace any custom <a>ReaderT</a>-monad-stack that
--   you're using with <a>Enter</a>.) If you don't use combinators that
--   require any context entries, you can just use <a>serve</a> as always.
--   
--   If you are using combinators that require a non-empty <a>Context</a>
--   you have to use <a>serveWithContext</a> and pass it a <a>Context</a>
--   that contains all the values your combinators need. A <a>Context</a>
--   is essentially a heterogenous list and accessing the elements is being
--   done by type (see <a>getContextEntry</a>). The parameter of the type
--   <a>Context</a> is a type-level list reflecting the types of the
--   contained context entries. To create a <a>Context</a> with entries,
--   use the operator <tt>(<a>:.</a>)</tt>:
--   
--   <pre>
--   &gt;&gt;&gt; :type True :. () :. EmptyContext
--   True :. () :. EmptyContext :: Context '[Bool, ()]
--   </pre>
data Context contextTypes
[EmptyContext] :: Context '[]
[:.] :: x -> Context xs -> Context (x : xs)

-- | This class is used to access context entries in <a>Context</a>s.
--   <a>getContextEntry</a> returns the first value where the type matches:
--   
--   <pre>
--   &gt;&gt;&gt; getContextEntry (True :. False :. EmptyContext) :: Bool
--   True
--   </pre>
--   
--   If the <a>Context</a> does not contain an entry of the requested type,
--   you'll get an error:
--   
--   <pre>
--   &gt;&gt;&gt; getContextEntry (True :. False :. EmptyContext) :: String
--   ...
--   ...No instance for (HasContextEntry '[] [Char])
--   ...
--   </pre>
class HasContextEntry (context :: [*]) (val :: *)
getContextEntry :: HasContextEntry context val => Context context -> val

-- | Normally context entries are accessed by their types. In case you need
--   to have multiple values of the same type in your <a>Context</a> and
--   need to access them, we provide <a>NamedContext</a>. You can think of
--   it as sub-namespaces for <a>Context</a>s.
data NamedContext (name :: Symbol) (subContext :: [*])
NamedContext :: (Context subContext) -> NamedContext

-- | <a>descendIntoNamedContext</a> allows you to access
--   <a>NamedContext</a>s. Usually you won't have to use it yourself but
--   instead use a combinator like <a>WithNamedContext</a>.
--   
--   This is how <a>descendIntoNamedContext</a> works:
--   
--   <pre>
--   &gt;&gt;&gt; :set -XFlexibleContexts
--   
--   &gt;&gt;&gt; let subContext = True :. EmptyContext
--   
--   &gt;&gt;&gt; :type subContext
--   subContext :: Context '[Bool]
--   
--   &gt;&gt;&gt; let parentContext = False :. (NamedContext subContext :: NamedContext "subContext" '[Bool]) :. EmptyContext
--   
--   &gt;&gt;&gt; :type parentContext
--   parentContext :: Context '[Bool, NamedContext "subContext" '[Bool]]
--   
--   &gt;&gt;&gt; descendIntoNamedContext (Proxy :: Proxy "subContext") parentContext :: Context '[Bool]
--   True :. EmptyContext
--   </pre>
descendIntoNamedContext :: forall context name subContext. HasContextEntry context (NamedContext name subContext) => Proxy (name :: Symbol) -> Context context -> Context subContext
instance GHC.Show.Show (Servant.Server.Internal.Context.Context '[])
instance (GHC.Show.Show a, GHC.Show.Show (Servant.Server.Internal.Context.Context as)) => GHC.Show.Show (Servant.Server.Internal.Context.Context (a : as))
instance GHC.Classes.Eq (Servant.Server.Internal.Context.Context '[])
instance (GHC.Classes.Eq a, GHC.Classes.Eq (Servant.Server.Internal.Context.Context as)) => GHC.Classes.Eq (Servant.Server.Internal.Context.Context (a : as))
instance Servant.Server.Internal.Context.HasContextEntry xs val => Servant.Server.Internal.Context.HasContextEntry (notIt : xs) val
instance Servant.Server.Internal.Context.HasContextEntry (val : xs) val

module Servant.Server.Internal.ServantErr
data ServantErr
ServantErr :: Int -> String -> ByteString -> [Header] -> ServantErr
[errHTTPCode] :: ServantErr -> Int
[errReasonPhrase] :: ServantErr -> String
[errBody] :: ServantErr -> ByteString
[errHeaders] :: ServantErr -> [Header]
type Handler = ExceptT ServantErr IO
responseServantErr :: ServantErr -> Response

-- | <a>err300</a> Multiple Choices
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err300 { errBody = "I can't choose." }
--   </pre>
err300 :: ServantErr

-- | <a>err301</a> Moved Permanently
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err301
--   </pre>
err301 :: ServantErr

-- | <a>err302</a> Found
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err302
--   </pre>
err302 :: ServantErr

-- | <a>err303</a> See Other
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err303
--   </pre>
err303 :: ServantErr

-- | <a>err304</a> Not Modified
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err304
--   </pre>
err304 :: ServantErr

-- | <a>err305</a> Use Proxy
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err305
--   </pre>
err305 :: ServantErr

-- | <a>err307</a> Temporary Redirect
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err307
--   </pre>
err307 :: ServantErr

-- | <a>err400</a> Bad Request
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err400 { errBody = "Your request makes no sense to me." }
--   </pre>
err400 :: ServantErr

-- | <a>err401</a> Unauthorized
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err401 { errBody = "Your credentials are invalid." }
--   </pre>
err401 :: ServantErr

-- | <a>err402</a> Payment Required
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err402 { errBody = "You have 0 credits. Please give me $$$." }
--   </pre>
err402 :: ServantErr

-- | <a>err403</a> Forbidden
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err403 { errBody = "Please login first." }
--   </pre>
err403 :: ServantErr

-- | <a>err404</a> Not Found
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err404 { errBody = "(╯°□°)╯︵ ┻━┻)." }
--   </pre>
err404 :: ServantErr

-- | <a>err405</a> Method Not Allowed
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err405 { errBody = "Your account privileges does not allow for this.  Please pay $$$." }
--   </pre>
err405 :: ServantErr

-- | <a>err406</a> Not Acceptable
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err406
--   </pre>
err406 :: ServantErr

-- | <a>err407</a> Proxy Authentication Required
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err407
--   </pre>
err407 :: ServantErr

-- | <a>err409</a> Conflict
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err409 { errBody = "Transaction conflicts with 59879cb56c7c159231eeacdd503d755f7e835f74" }
--   </pre>
err409 :: ServantErr

-- | <a>err410</a> Gone
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err410 { errBody = "I know it was here at some point, but.. I blame bad luck." }
--   </pre>
err410 :: ServantErr

-- | <a>err411</a> Length Required
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err411
--   </pre>
err411 :: ServantErr

-- | <a>err412</a> Precondition Failed
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err412 { errBody = "Precondition fail: x &lt; 42 &amp;&amp; y &gt; 57" }
--   </pre>
err412 :: ServantErr

-- | <a>err413</a> Request Entity Too Large
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err413 { errBody = "Request exceeded 64k." }
--   </pre>
err413 :: ServantErr

-- | <a>err414</a> Request-URI Too Large
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err414 { errBody = "Maximum length is 64." }
--   </pre>
err414 :: ServantErr

-- | <a>err415</a> Unsupported Media Type
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err415 { errBody = "Supported media types:  gif, png" }
--   </pre>
err415 :: ServantErr

-- | <a>err416</a> Request range not satisfiable
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err416 { errBody = "Valid range is [0, 424242]." }
--   </pre>
err416 :: ServantErr

-- | <a>err417</a> Expectation Failed
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err417 { errBody = "I found a quux in the request.  This isn't going to work." }
--   </pre>
err417 :: ServantErr

-- | <a>err500</a> Internal Server Error
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err500 { errBody = "Exception in module A.B.C:55.  Have a great day!" }
--   </pre>
err500 :: ServantErr

-- | <a>err501</a> Not Implemented
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err501 { errBody = "/v1/foo is not supported with quux in the request." }
--   </pre>
err501 :: ServantErr

-- | <a>err502</a> Bad Gateway
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err502 { errBody = "Tried gateway foo, bar, and baz.  None responded." }
--   </pre>
err502 :: ServantErr

-- | <a>err503</a> Service Unavailable
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err503 { errBody = "We're rewriting in PHP." }
--   </pre>
err503 :: ServantErr

-- | <a>err504</a> Gateway Time-out
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err504 { errBody = "Backend foobar did not respond in 5 seconds." }
--   </pre>
err504 :: ServantErr

-- | <a>err505</a> HTTP Version not supported
--   
--   Example usage:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err505 { errBody = "I support HTTP/4.0 only." }
--   </pre>
err505 :: ServantErr
instance GHC.Read.Read Servant.Server.Internal.ServantErr.ServantErr
instance GHC.Classes.Eq Servant.Server.Internal.ServantErr.ServantErr
instance GHC.Show.Show Servant.Server.Internal.ServantErr.ServantErr
instance GHC.Exception.Exception Servant.Server.Internal.ServantErr.ServantErr

module Servant.Server.Internal.RoutingApplication
type RoutingApplication = Request  the request, the field 'pathInfo' may be modified by url routing -> (RouteResult Response -> IO ResponseReceived) -> IO ResponseReceived

-- | The result of matching against a path in the route tree.
data RouteResult a

-- | Keep trying other paths. The <tt>ServantErr</tt> should only be 404,
--   405 or 406.
Fail :: ServantErr -> RouteResult a

-- | Don't try other paths.
FailFatal :: !ServantErr -> RouteResult a
Route :: !a -> RouteResult a
toApplication :: RoutingApplication -> Application

-- | A <a>Delayed</a> is a representation of a handler with scheduled
--   delayed checks that can trigger errors.
--   
--   Why would we want to delay checks?
--   
--   There are two reasons:
--   
--   <ol>
--   <li>In a straight-forward implementation, the order in which we
--   perform checks will determine the error we generate. This is because
--   once an error occurs, we would abort and not perform any subsequent
--   checks, but rather return the current error.</li>
--   </ol>
--   
--   This is not a necessity: we could continue doing other checks, and
--   choose the preferred error. However, that would in general mean more
--   checking, which leads us to the other reason.
--   
--   <ol>
--   <li>We really want to avoid doing certain checks too early. For
--   example, captures involve parsing, and are much more costly than
--   static route matches. In particular, if several paths contain the
--   "same" capture, we'd like as much as possible to avoid trying the same
--   parse many times. Also tricky is the request body. Again, this
--   involves parsing, but also, WAI makes obtaining the request body a
--   side-effecting operation. We could/can work around this by manually
--   caching the request body, but we'd rather keep the number of times we
--   actually try to decode the request body to an absolute minimum.</li>
--   </ol>
--   
--   We prefer to have the following relative priorities of error codes:
--   
--   <pre>
--   404
--   405 (bad method)
--   401 (unauthorized)
--   415 (unsupported media type)
--   400 (bad request)
--   406 (not acceptable)
--   </pre>
--   
--   Therefore, while routing, we delay most checks so that they will
--   ultimately occur in the right order.
--   
--   A <a>Delayed</a> contains three delayed blocks of tests, and the
--   actual handler:
--   
--   <ol>
--   <li>Delayed captures. These can actually cause 404, and while they're
--   costly, they should be done first among the delayed checks (at least
--   as long as we do not decouple the check order from the error
--   reporting, see above). Delayed captures can provide inputs to the
--   actual handler.</li>
--   <li>Method check(s). This can cause a 405. On success, it does not
--   provide an input for the handler. Method checks are comparatively
--   cheap.</li>
--   <li>Body and accept header checks. The request body check can cause
--   both 400 and 415. This provides an input to the handler. The accept
--   header check can be performed as the final computation in this block.
--   It can cause a 406.</li>
--   </ol>
data Delayed env c
[Delayed] :: {capturesD :: env -> DelayedIO captures, methodD :: DelayedIO (), authD :: DelayedIO auth, bodyD :: DelayedIO body, serverD :: captures -> auth -> body -> Request -> RouteResult c} -> Delayed env c

-- | Computations used in a <a>Delayed</a> can depend on the incoming
--   <a>Request</a>, may perform 'IO, and result in a 'RouteResult, meaning
--   they can either suceed, fail (with the possibility to recover), or
--   fail fatally.
newtype DelayedIO a
DelayedIO :: (Request -> IO (RouteResult a)) -> DelayedIO a
[runDelayedIO] :: DelayedIO a -> Request -> IO (RouteResult a)

-- | A <a>Delayed</a> without any stored checks.
emptyDelayed :: RouteResult a -> Delayed env a

-- | Fail with the option to recover.
delayedFail :: ServantErr -> DelayedIO a

-- | Fail fatally, i.e., without any option to recover.
delayedFailFatal :: ServantErr -> DelayedIO a

-- | Gain access to the incoming request.
withRequest :: (Request -> DelayedIO a) -> DelayedIO a

-- | Add a capture to the end of the capture block.
addCapture :: Delayed env (a -> b) -> (captured -> DelayedIO a) -> Delayed (captured, env) b

-- | Add a method check to the end of the method block.
addMethodCheck :: Delayed env a -> DelayedIO () -> Delayed env a

-- | Add an auth check to the end of the auth block.
addAuthCheck :: Delayed env (a -> b) -> DelayedIO a -> Delayed env b

-- | Add a body check to the end of the body block.
addBodyCheck :: Delayed env (a -> b) -> DelayedIO a -> Delayed env b

-- | Add an accept header check to the beginning of the body block. There
--   is a tradeoff here. In principle, we'd like to take a bad body (400)
--   response take precedence over a failed accept check (406). BUT to
--   allow streaming the body, we cannot run the body check and then still
--   backtrack. We therefore do the accept check before the body check,
--   when we can still backtrack. There are other solutions to this, but
--   they'd be more complicated (such as delaying the body check further so
--   that it can still be run in a situation where we'd otherwise report
--   406).
addAcceptCheck :: Delayed env a -> DelayedIO () -> Delayed env a

-- | Many combinators extract information that is passed to the handler
--   without the possibility of failure. In such a case,
--   <a>passToServer</a> can be used.
passToServer :: Delayed env (a -> b) -> (Request -> a) -> Delayed env b

-- | Run a delayed server. Performs all scheduled operations in order, and
--   passes the results from the capture and body blocks on to the actual
--   handler.
--   
--   This should only be called once per request; otherwise the guarantees
--   about effect and HTTP error ordering break down.
runDelayed :: Delayed env a -> env -> Request -> IO (RouteResult a)

-- | Runs a delayed server and the resulting action. Takes a continuation
--   that lets us send a response. Also takes a continuation for how to
--   turn the result of the delayed server into a response.
runAction :: Delayed env (Handler a) -> env -> Request -> (RouteResult Response -> IO r) -> (a -> RouteResult Response) -> IO r
instance GHC.Base.Functor Servant.Server.Internal.RoutingApplication.RouteResult
instance GHC.Read.Read a => GHC.Read.Read (Servant.Server.Internal.RoutingApplication.RouteResult a)
instance GHC.Show.Show a => GHC.Show.Show (Servant.Server.Internal.RoutingApplication.RouteResult a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Servant.Server.Internal.RoutingApplication.RouteResult a)
instance GHC.Base.Functor (Servant.Server.Internal.RoutingApplication.Delayed env)
instance GHC.Base.Functor Servant.Server.Internal.RoutingApplication.DelayedIO
instance GHC.Base.Applicative Servant.Server.Internal.RoutingApplication.DelayedIO
instance GHC.Base.Monad Servant.Server.Internal.RoutingApplication.DelayedIO
instance Control.Monad.IO.Class.MonadIO Servant.Server.Internal.RoutingApplication.DelayedIO

module Servant.Server.Internal.BasicAuth

-- | servant-server's current implementation of basic authentication is not
--   immune to certian kinds of timing attacks. Decoding payloads does not
--   take a fixed amount of time.
--   
--   The result of authentication/authorization
data BasicAuthResult usr
Unauthorized :: BasicAuthResult usr
BadPassword :: BasicAuthResult usr
NoSuchUser :: BasicAuthResult usr
Authorized :: usr -> BasicAuthResult usr

-- | Datatype wrapping a function used to check authentication.
newtype BasicAuthCheck usr
BasicAuthCheck :: (BasicAuthData -> IO (BasicAuthResult usr)) -> BasicAuthCheck usr
[unBasicAuthCheck] :: BasicAuthCheck usr -> BasicAuthData -> IO (BasicAuthResult usr)

-- | Internal method to make a basic-auth challenge
mkBAChallengerHdr :: ByteString -> Header

-- | Find and decode an <tt>Authorization</tt> header from the request as
--   Basic Auth
decodeBAHdr :: Request -> Maybe BasicAuthData

-- | Run and check basic authentication, returning the appropriate http
--   error per the spec.
runBasicAuth :: Request -> ByteString -> BasicAuthCheck usr -> DelayedIO usr
instance GHC.Base.Functor Servant.Server.Internal.BasicAuth.BasicAuthCheck
instance GHC.Generics.Generic (Servant.Server.Internal.BasicAuth.BasicAuthCheck usr)
instance GHC.Base.Functor Servant.Server.Internal.BasicAuth.BasicAuthResult
instance GHC.Generics.Generic (Servant.Server.Internal.BasicAuth.BasicAuthResult usr)
instance GHC.Read.Read usr => GHC.Read.Read (Servant.Server.Internal.BasicAuth.BasicAuthResult usr)
instance GHC.Show.Show usr => GHC.Show.Show (Servant.Server.Internal.BasicAuth.BasicAuthResult usr)
instance GHC.Classes.Eq usr => GHC.Classes.Eq (Servant.Server.Internal.BasicAuth.BasicAuthResult usr)

module Servant.Server.Internal.Router
type Router env = Router' env RoutingApplication

-- | Internal representation of a router.
--   
--   The first argument describes an environment type that is expected as
--   extra input by the routers at the leaves. The environment is filled
--   while running the router, with path components that can be used to
--   process captures.
data Router' env a

-- | the map contains routers for subpaths (first path component used for
--   lookup and removed afterwards), the list contains handlers for the
--   empty path, to be tried in order
StaticRouter :: (Map Text (Router' env a)) -> [env -> a] -> Router' env a

-- | first path component is passed to the child router in its environment
--   and removed afterwards
CaptureRouter :: (Router' (Text, env) a) -> Router' env a

-- | all path components are passed to the child router in its environment
--   and are removed afterwards
CaptureAllRouter :: (Router' ([Text], env) a) -> Router' env a

-- | to be used for routes we do not know anything about
RawRouter :: (env -> a) -> Router' env a

-- | left-biased choice between two routers
Choice :: (Router' env a) -> (Router' env a) -> Router' env a

-- | Smart constructor for a single static path component.
pathRouter :: Text -> Router' env a -> Router' env a

-- | Smart constructor for a leaf, i.e., a router that expects the empty
--   path.
leafRouter :: (env -> a) -> Router' env a

-- | Smart constructor for the choice between routers. We currently
--   optimize the following cases:
--   
--   <ul>
--   <li>Two static routers can be joined by joining their maps and
--   concatenating their leaf-lists.</li>
--   <li>Two dynamic routers can be joined by joining their codomains.</li>
--   <li>Choice nodes can be reordered.</li>
--   </ul>
choice :: Router' env a -> Router' env a -> Router' env a

-- | Datatype used for representing and debugging the structure of a
--   router. Abstracts from the handlers at the leaves.
--   
--   Two <a>Router</a>s can be structurally compared by computing their
--   <a>RouterStructure</a> using <a>routerStructure</a> and then testing
--   for equality, see <a>sameStructure</a>.
data RouterStructure
StaticRouterStructure :: (Map Text RouterStructure) -> Int -> RouterStructure
CaptureRouterStructure :: RouterStructure -> RouterStructure
RawRouterStructure :: RouterStructure
ChoiceStructure :: RouterStructure -> RouterStructure -> RouterStructure

-- | Compute the structure of a router.
--   
--   Assumes that the request or text being passed in <tt>WithRequest</tt>
--   or <a>CaptureRouter</a> does not affect the structure of the
--   underlying tree.
routerStructure :: Router' env a -> RouterStructure

-- | Compare the structure of two routers.
sameStructure :: Router' env a -> Router' env b -> Bool

-- | Provide a textual representation of the structure of a router.
routerLayout :: Router' env a -> Text

-- | Apply a transformation to the response of a <a>Router</a>.
tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router env -> Router env

-- | Interpret a router as an application.
runRouter :: Router () -> RoutingApplication
runRouterEnv :: Router env -> env -> RoutingApplication

-- | Try a list of routing applications in order. We stop as soon as one
--   fails fatally or succeeds. If all fail normally, we pick the "best"
--   error.
runChoice :: [env -> RoutingApplication] -> env -> RoutingApplication
worseHTTPCode :: Int -> Int -> Bool
instance GHC.Show.Show Servant.Server.Internal.Router.RouterStructure
instance GHC.Classes.Eq Servant.Server.Internal.Router.RouterStructure
instance GHC.Base.Functor (Servant.Server.Internal.Router.Router' env)

module Servant.Server.Internal
class HasServer api context where type ServerT api (m :: * -> *) :: * where {
    type family ServerT api (m :: * -> *) :: *;
}
route :: HasServer api context => Proxy api -> Context context -> Delayed env (Server api) -> Router env
type Server api = ServerT api Handler

-- | A server for <tt>a <a>:&lt;|&gt;</a> b</tt> first tries to match the
--   request against the route represented by <tt>a</tt> and if it fails
--   tries <tt>b</tt>. You must provide a request handler for each route.
--   
--   <pre>
--   type MyApi = "books" :&gt; Get '[JSON] [Book] -- GET /books
--           :&lt;|&gt; "books" :&gt; ReqBody Book :&gt; Post '[JSON] Book -- POST /books
--   
--   server :: Server MyApi
--   server = listAllBooks :&lt;|&gt; postBook
--     where listAllBooks = ...
--           postBook book = ...
--   </pre>

-- | If you use <a>Capture</a> in one of the endpoints for your API, this
--   automatically requires your server-side handler to be a function that
--   takes an argument of the type specified by the <a>Capture</a>. This
--   lets servant worry about getting it from the URL and turning it into a
--   value of the type you specify.
--   
--   You can control how it'll be converted from <tt>Text</tt> to your type
--   by simply providing an instance of <a>FromHttpApiData</a> for your
--   type.
--   
--   Example:
--   
--   <pre>
--   type MyApi = "books" :&gt; Capture "isbn" Text :&gt; Get '[JSON] Book
--   
--   server :: Server MyApi
--   server = getBook
--     where getBook :: Text -&gt; Handler Book
--           getBook isbn = ...
--   </pre>

-- | If you use <a>CaptureAll</a> in one of the endpoints for your API,
--   this automatically requires your server-side handler to be a function
--   that takes an argument of a list of the type specified by the
--   <a>CaptureAll</a>. This lets servant worry about getting values from
--   the URL and turning them into values of the type you specify.
--   
--   You can control how they'll be converted from <tt>Text</tt> to your
--   type by simply providing an instance of <a>FromHttpApiData</a> for
--   your type.
--   
--   Example:
--   
--   <pre>
--   type MyApi = "src" :&gt; CaptureAll "segments" Text :&gt; Get '[JSON] SourceFile
--   
--   server :: Server MyApi
--   server = getSourceFile
--     where getSourceFile :: [Text] -&gt; Handler Book
--           getSourceFile pathSegments = ...
--   </pre>
allowedMethodHead :: Method -> Request -> Bool
allowedMethod :: Method -> Request -> Bool
processMethodRouter :: Maybe (ByteString, ByteString) -> Status -> Method -> Maybe [(HeaderName, ByteString)] -> Request -> RouteResult Response
methodCheck :: Method -> Request -> DelayedIO ()
acceptCheck :: (AllMime list) => Proxy list -> ByteString -> DelayedIO ()
methodRouter :: (AllCTRender ctypes a) => Method -> Proxy ctypes -> Status -> Delayed env (Handler a) -> Router env
methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v) => Method -> Proxy ctypes -> Status -> Delayed env (Handler (Headers h v)) -> Router env

-- | If you use <a>Header</a> in one of the endpoints for your API, this
--   automatically requires your server-side handler to be a function that
--   takes an argument of the type specified by <a>Header</a>. This lets
--   servant worry about extracting it from the request and turning it into
--   a value of the type you specify.
--   
--   All it asks is for a <a>FromHttpApiData</a> instance.
--   
--   Example:
--   
--   <pre>
--   newtype Referer = Referer Text
--     deriving (Eq, Show, FromHttpApiData)
--   
--              -- GET /view-my-referer
--   type MyApi = "view-my-referer" :&gt; Header "Referer" Referer :&gt; Get '[JSON] Referer
--   
--   server :: Server MyApi
--   server = viewReferer
--     where viewReferer :: Referer -&gt; Handler referer
--           viewReferer referer = return referer
--   </pre>

-- | If you use <tt><a>QueryParam</a> "author" Text</tt> in one of the
--   endpoints for your API, this automatically requires your server-side
--   handler to be a function that takes an argument of type
--   <tt><a>Maybe</a> <tt>Text</tt></tt>.
--   
--   This lets servant worry about looking it up in the query string and
--   turning it into a value of the type you specify, enclosed in
--   <a>Maybe</a>, because it may not be there and servant would then hand
--   you <a>Nothing</a>.
--   
--   You can control how it'll be converted from <tt>Text</tt> to your type
--   by simply providing an instance of <a>FromHttpApiData</a> for your
--   type.
--   
--   Example:
--   
--   <pre>
--   type MyApi = "books" :&gt; QueryParam "author" Text :&gt; Get '[JSON] [Book]
--   
--   server :: Server MyApi
--   server = getBooksBy
--     where getBooksBy :: Maybe Text -&gt; Handler [Book]
--           getBooksBy Nothing       = ...return all books...
--           getBooksBy (Just author) = ...return books by the given author...
--   </pre>

-- | If you use <tt><a>QueryParams</a> "authors" Text</tt> in one of the
--   endpoints for your API, this automatically requires your server-side
--   handler to be a function that takes an argument of type
--   <tt>[<tt>Text</tt>]</tt>.
--   
--   This lets servant worry about looking up 0 or more values in the query
--   string associated to <tt>authors</tt> and turning each of them into a
--   value of the type you specify.
--   
--   You can control how the individual values are converted from
--   <tt>Text</tt> to your type by simply providing an instance of
--   <a>FromHttpApiData</a> for your type.
--   
--   Example:
--   
--   <pre>
--   type MyApi = "books" :&gt; QueryParams "authors" Text :&gt; Get '[JSON] [Book]
--   
--   server :: Server MyApi
--   server = getBooksBy
--     where getBooksBy :: [Text] -&gt; Handler [Book]
--           getBooksBy authors = ...return all books by these authors...
--   </pre>

-- | If you use <tt><a>QueryFlag</a> "published"</tt> in one of the
--   endpoints for your API, this automatically requires your server-side
--   handler to be a function that takes an argument of type <a>Bool</a>.
--   
--   Example:
--   
--   <pre>
--   type MyApi = "books" :&gt; QueryFlag "published" :&gt; Get '[JSON] [Book]
--   
--   server :: Server MyApi
--   server = getBooks
--     where getBooks :: Bool -&gt; Handler [Book]
--           getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
--   </pre>

-- | Just pass the request to the underlying application and serve its
--   response.
--   
--   Example:
--   
--   <pre>
--   type MyApi = "images" :&gt; Raw
--   
--   server :: Server MyApi
--   server = serveDirectory "/var/www/images"
--   </pre>

-- | If you use <a>ReqBody</a> in one of the endpoints for your API, this
--   automatically requires your server-side handler to be a function that
--   takes an argument of the type specified by <a>ReqBody</a>. The
--   <tt>Content-Type</tt> header is inspected, and the list provided is
--   used to attempt deserialization. If the request does not have a
--   <tt>Content-Type</tt> header, it is treated as
--   <tt>application/octet-stream</tt> (as specified in <a>RFC7231</a>.
--   This lets servant worry about extracting it from the request and
--   turning it into a value of the type you specify.
--   
--   All it asks is for a <tt>FromJSON</tt> instance.
--   
--   Example:
--   
--   <pre>
--   type MyApi = "books" :&gt; ReqBody '[JSON] Book :&gt; Post '[JSON] Book
--   
--   server :: Server MyApi
--   server = postBook
--     where postBook :: Book -&gt; Handler Book
--           postBook book = ...insert into your db...
--   </pre>

-- | Make sure the incoming request starts with <tt>"/path"</tt>, strip it
--   and pass the rest of the request path to <tt>api</tt>.

-- | Basic Authentication
ct_wildcard :: ByteString
instance (Servant.Server.Internal.HasServer a context, Servant.Server.Internal.HasServer b context) => Servant.Server.Internal.HasServer (a Servant.API.Alternative.:<|> b) context
instance forall k1 (capture :: GHC.Types.Symbol) a (api :: k1) (context :: [*]). (GHC.TypeLits.KnownSymbol capture, Web.HttpApiData.Internal.FromHttpApiData a, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.Capture.Capture capture a Servant.API.Sub.:> api) context
instance forall k1 (capture :: GHC.Types.Symbol) a (sublayout :: k1) (context :: [*]). (GHC.TypeLits.KnownSymbol capture, Web.HttpApiData.Internal.FromHttpApiData a, Servant.Server.Internal.HasServer sublayout context) => Servant.Server.Internal.HasServer (Servant.API.Capture.CaptureAll capture a Servant.API.Sub.:> sublayout) context
instance forall k1 (ctypes :: [GHC.Types.*]) a (method :: k1) (status :: GHC.Types.Nat) (context :: [*]). (Servant.API.ContentTypes.AllCTRender ctypes a, Servant.API.Verbs.ReflectMethod method, GHC.TypeLits.KnownNat status) => Servant.Server.Internal.HasServer (Servant.API.Verbs.Verb method status ctypes a) context
instance forall k1 (ctypes :: [GHC.Types.*]) a (method :: k1) (status :: GHC.Types.Nat) (h :: [*]) (context :: [*]). (Servant.API.ContentTypes.AllCTRender ctypes a, Servant.API.Verbs.ReflectMethod method, GHC.TypeLits.KnownNat status, Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.Headers h a)) => Servant.Server.Internal.HasServer (Servant.API.Verbs.Verb method status ctypes (Servant.API.ResponseHeaders.Headers h a)) context
instance forall k1 (sym :: GHC.Types.Symbol) a (api :: k1) (context :: [*]). (GHC.TypeLits.KnownSymbol sym, Web.HttpApiData.Internal.FromHttpApiData a, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.Header.Header sym a Servant.API.Sub.:> api) context
instance forall k1 (sym :: GHC.Types.Symbol) a (api :: k1) (context :: [*]). (GHC.TypeLits.KnownSymbol sym, Web.HttpApiData.Internal.FromHttpApiData a, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryParam sym a Servant.API.Sub.:> api) context
instance forall k1 (sym :: GHC.Types.Symbol) a (api :: k1) (context :: [*]). (GHC.TypeLits.KnownSymbol sym, Web.HttpApiData.Internal.FromHttpApiData a, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryParams sym a Servant.API.Sub.:> api) context
instance forall k1 (sym :: GHC.Types.Symbol) (api :: k1) (context :: [*]). (GHC.TypeLits.KnownSymbol sym, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.QueryParam.QueryFlag sym Servant.API.Sub.:> api) context
instance Servant.Server.Internal.HasServer Servant.API.Raw.Raw context
instance forall k1 (list :: [GHC.Types.*]) a (api :: k1) (context :: [*]). (Servant.API.ContentTypes.AllCTUnrender list a, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (Servant.API.ReqBody.ReqBody list a Servant.API.Sub.:> api) context
instance forall k1 (path :: GHC.Types.Symbol) (api :: k1) (context :: [*]). (GHC.TypeLits.KnownSymbol path, Servant.Server.Internal.HasServer api context) => Servant.Server.Internal.HasServer (path Servant.API.Sub.:> api) context
instance forall k1 (api :: k1) (context :: [*]). Servant.Server.Internal.HasServer api context => Servant.Server.Internal.HasServer (Servant.API.RemoteHost.RemoteHost Servant.API.Sub.:> api) context
instance forall k1 (api :: k1) (context :: [*]). Servant.Server.Internal.HasServer api context => Servant.Server.Internal.HasServer (Servant.API.IsSecure.IsSecure Servant.API.Sub.:> api) context
instance forall k1 (api :: k1) (context :: [*]). Servant.Server.Internal.HasServer api context => Servant.Server.Internal.HasServer (Data.Vault.Lazy.Vault Servant.API.Sub.:> api) context
instance forall k1 (api :: k1) (context :: [*]). Servant.Server.Internal.HasServer api context => Servant.Server.Internal.HasServer (Network.HTTP.Types.Version.HttpVersion Servant.API.Sub.:> api) context
instance forall k1 (realm :: GHC.Types.Symbol) (api :: k1) (context :: [*]) usr. (GHC.TypeLits.KnownSymbol realm, Servant.Server.Internal.HasServer api context, Servant.Server.Internal.Context.HasContextEntry context (Servant.Server.Internal.BasicAuth.BasicAuthCheck usr)) => Servant.Server.Internal.HasServer (Servant.API.BasicAuth.BasicAuth realm usr Servant.API.Sub.:> api) context
instance (Servant.Server.Internal.Context.HasContextEntry context (Servant.Server.Internal.Context.NamedContext name subContext), Servant.Server.Internal.HasServer subApi subContext) => Servant.Server.Internal.HasServer (Servant.API.WithNamedContext.WithNamedContext name subContext subApi) context


-- | This module lets you implement <a>Server</a>s for defined APIs. You'll
--   most likely just need <a>serve</a>.
module Servant.Server

-- | <a>serve</a> allows you to implement an API and produce a wai
--   <a>Application</a>.
--   
--   Example:
--   
--   <pre>
--   type MyApi = "books" :&gt; Get '[JSON] [Book] -- GET /books
--           :&lt;|&gt; "books" :&gt; ReqBody Book :&gt; Post '[JSON] Book -- POST /books
--   
--   server :: Server MyApi
--   server = listAllBooks :&lt;|&gt; postBook
--     where listAllBooks = ...
--           postBook book = ...
--   
--   myApi :: Proxy MyApi
--   myApi = Proxy
--   
--   app :: Application
--   app = serve myApi server
--   
--   main :: IO ()
--   main = Network.Wai.Handler.Warp.run 8080 app
--   </pre>
serve :: (HasServer api '[]) => Proxy api -> Server api -> Application
serveWithContext :: (HasServer api context) => Proxy api -> Context context -> Server api -> Application
toApplication :: RoutingApplication -> Application
class HasServer api context where type ServerT api (m :: * -> *) :: * where {
    type family ServerT api (m :: * -> *) :: *;
}
route :: HasServer api context => Proxy api -> Context context -> Delayed env (Server api) -> Router env
type Server api = ServerT api Handler
type Handler = ExceptT ServantErr IO

-- | The function <a>layout</a> produces a textual description of the
--   internal router layout for debugging purposes. Note that the router
--   layout is determined just by the API, not by the handlers.
--   
--   Example:
--   
--   For the following API
--   
--   <pre>
--   type API =
--          "a" :&gt; "d" :&gt; Get '[JSON] NoContent
--     :&lt;|&gt; "b" :&gt; Capture "x" Int :&gt; Get '[JSON] Bool
--     :&lt;|&gt; "c" :&gt; Put '[JSON] Bool
--     :&lt;|&gt; "a" :&gt; "e" :&gt; Get '[JSON] Int
--     :&lt;|&gt; "b" :&gt; Capture "x" Int :&gt; Put '[JSON] Bool
--     :&lt;|&gt; Raw
--   </pre>
--   
--   we get the following output:
--   
--   <pre>
--   /
--   ├─ a/
--   │  ├─ d/
--   │  │  └─•
--   │  └─ e/
--   │     └─•
--   ├─ b/
--   │  └─ &lt;capture&gt;/
--   │     ├─•
--   │     ┆
--   │     └─•
--   ├─ c/
--   │  └─•
--   ┆
--   └─ &lt;raw&gt;
--   </pre>
--   
--   Explanation of symbols:
--   
--   <ul>
--   <li><i><tt>├</tt></i> Normal lines reflect static branching via a
--   table.</li>
--   <li><i><tt>a/</tt></i> Nodes reflect static path components.</li>
--   <li><i><tt>─•</tt></i> Leaves reflect endpoints.</li>
--   <li><i><tt>&lt;capture&gt;/</tt></i> This is a delayed capture of a
--   path component.</li>
--   <li><i><tt>&lt;raw&gt;</tt></i> This is a part of the API we do not
--   know anything about.</li>
--   <li><i><tt>┆</tt></i> Dashed lines suggest a dynamic choice between
--   the part above and below. If there is a success for fatal failure in
--   the first part, that one takes precedence. If both parts fail, the
--   "better" error code will be returned.</li>
--   </ul>
layout :: (HasServer api '[]) => Proxy api -> Text

-- | Variant of <a>layout</a> that takes an additional <a>Context</a>.
layoutWithContext :: (HasServer api context) => Proxy api -> Context context -> Text
enter :: Enter typ arg ret => arg -> typ -> ret

-- | A natural transformation from <tt>m</tt> to <tt>n</tt>. Used to
--   <a>enter</a> particular datatypes.
newtype (:~>) (m :: * -> *) (n :: * -> *) :: (* -> *) -> (* -> *) -> *
Nat :: (forall a. m a -> n a) -> (:~>)
[unNat] :: (:~>) -> forall a. m a -> n a

-- | Like <a>lift</a>.
liftNat :: (MonadTrans t, Monad m) => (:~>) m (t m)
runReaderTNat :: r -> (:~>) (ReaderT * r m) m
evalStateTLNat :: Monad m => s -> (:~>) (StateT s m) m
evalStateTSNat :: Monad m => s -> (:~>) (StateT s m) m

-- | Like <a>logWriterTSNat</a>, but for strict <tt>WriterT</tt>.
logWriterTLNat :: MonadIO m => (w -> IO ()) -> (:~>) (WriterT w m) m

-- | Log the contents of <a>WriterT</a> with the function provided as the
--   first argument, and return the value of the <tt>WriterT</tt>
--   computation
logWriterTSNat :: MonadIO m => (w -> IO ()) -> (:~>) (WriterT w m) m

-- | Like <tt>mmorph</tt>'s <a>hoist</a>.
hoistNat :: (MFunctor t, Monad m) => (:~>) m n -> (:~>) (t m) (t n)

-- | Like <tt>mmorph</tt>'s <a>embed</a>.
embedNat :: (MMonad t, Monad n) => (:~>) m (t n) -> (:~>) (t m) (t n)

-- | Like <tt>mmorph</tt>'s <a>squash</a>.
squashNat :: (Monad m, MMonad t) => (:~>) (t (t m)) (t m)

-- | Like <tt>mmorph</tt>'s <a>generalize</a>.
generalizeNat :: Applicative m => (:~>) Identity m

-- | Apply a transformation to the response of a <a>Router</a>.
tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router env -> Router env

-- | <a>Context</a>s are used to pass values to combinators. (They are
--   <b>not</b> meant to be used to pass parameters to your handlers, i.e.
--   they should not replace any custom <a>ReaderT</a>-monad-stack that
--   you're using with <a>Enter</a>.) If you don't use combinators that
--   require any context entries, you can just use <a>serve</a> as always.
--   
--   If you are using combinators that require a non-empty <a>Context</a>
--   you have to use <a>serveWithContext</a> and pass it a <a>Context</a>
--   that contains all the values your combinators need. A <a>Context</a>
--   is essentially a heterogenous list and accessing the elements is being
--   done by type (see <a>getContextEntry</a>). The parameter of the type
--   <a>Context</a> is a type-level list reflecting the types of the
--   contained context entries. To create a <a>Context</a> with entries,
--   use the operator <tt>(<a>:.</a>)</tt>:
--   
--   <pre>
--   &gt;&gt;&gt; :type True :. () :. EmptyContext
--   True :. () :. EmptyContext :: Context '[Bool, ()]
--   </pre>
data Context contextTypes
[EmptyContext] :: Context '[]
[:.] :: x -> Context xs -> Context (x : xs)

-- | This class is used to access context entries in <a>Context</a>s.
--   <a>getContextEntry</a> returns the first value where the type matches:
--   
--   <pre>
--   &gt;&gt;&gt; getContextEntry (True :. False :. EmptyContext) :: Bool
--   True
--   </pre>
--   
--   If the <a>Context</a> does not contain an entry of the requested type,
--   you'll get an error:
--   
--   <pre>
--   &gt;&gt;&gt; getContextEntry (True :. False :. EmptyContext) :: String
--   ...
--   ...No instance for (HasContextEntry '[] [Char])
--   ...
--   </pre>
class HasContextEntry (context :: [*]) (val :: *)
getContextEntry :: HasContextEntry context val => Context context -> val

-- | Normally context entries are accessed by their types. In case you need
--   to have multiple values of the same type in your <a>Context</a> and
--   need to access them, we provide <a>NamedContext</a>. You can think of
--   it as sub-namespaces for <a>Context</a>s.
data NamedContext (name :: Symbol) (subContext :: [*])
NamedContext :: (Context subContext) -> NamedContext

-- | <a>descendIntoNamedContext</a> allows you to access
--   <a>NamedContext</a>s. Usually you won't have to use it yourself but
--   instead use a combinator like <a>WithNamedContext</a>.
--   
--   This is how <a>descendIntoNamedContext</a> works:
--   
--   <pre>
--   &gt;&gt;&gt; :set -XFlexibleContexts
--   
--   &gt;&gt;&gt; let subContext = True :. EmptyContext
--   
--   &gt;&gt;&gt; :type subContext
--   subContext :: Context '[Bool]
--   
--   &gt;&gt;&gt; let parentContext = False :. (NamedContext subContext :: NamedContext "subContext" '[Bool]) :. EmptyContext
--   
--   &gt;&gt;&gt; :type parentContext
--   parentContext :: Context '[Bool, NamedContext "subContext" '[Bool]]
--   
--   &gt;&gt;&gt; descendIntoNamedContext (Proxy :: Proxy "subContext") parentContext :: Context '[Bool]
--   True :. EmptyContext
--   </pre>
descendIntoNamedContext :: forall context name subContext. HasContextEntry context (NamedContext name subContext) => Proxy (name :: Symbol) -> Context context -> Context subContext

-- | Datatype wrapping a function used to check authentication.
newtype BasicAuthCheck usr
BasicAuthCheck :: (BasicAuthData -> IO (BasicAuthResult usr)) -> BasicAuthCheck usr
[unBasicAuthCheck] :: BasicAuthCheck usr -> BasicAuthData -> IO (BasicAuthResult usr)

-- | servant-server's current implementation of basic authentication is not
--   immune to certian kinds of timing attacks. Decoding payloads does not
--   take a fixed amount of time.
--   
--   The result of authentication/authorization
data BasicAuthResult usr
Unauthorized :: BasicAuthResult usr
BadPassword :: BasicAuthResult usr
NoSuchUser :: BasicAuthResult usr
Authorized :: usr -> BasicAuthResult usr
data ServantErr
ServantErr :: Int -> String -> ByteString -> [Header] -> ServantErr
[errHTTPCode] :: ServantErr -> Int
[errReasonPhrase] :: ServantErr -> String
[errBody] :: ServantErr -> ByteString
[errHeaders] :: ServantErr -> [Header]

-- | <a>err300</a> Multiple Choices
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err300 { errBody = "I can't choose." }
--   </pre>
err300 :: ServantErr

-- | <a>err301</a> Moved Permanently
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err301
--   </pre>
err301 :: ServantErr

-- | <a>err302</a> Found
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err302
--   </pre>
err302 :: ServantErr

-- | <a>err303</a> See Other
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err303
--   </pre>
err303 :: ServantErr

-- | <a>err304</a> Not Modified
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err304
--   </pre>
err304 :: ServantErr

-- | <a>err305</a> Use Proxy
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err305
--   </pre>
err305 :: ServantErr

-- | <a>err307</a> Temporary Redirect
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err307
--   </pre>
err307 :: ServantErr

-- | <a>err400</a> Bad Request
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err400 { errBody = "Your request makes no sense to me." }
--   </pre>
err400 :: ServantErr

-- | <a>err401</a> Unauthorized
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err401 { errBody = "Your credentials are invalid." }
--   </pre>
err401 :: ServantErr

-- | <a>err402</a> Payment Required
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err402 { errBody = "You have 0 credits. Please give me $$$." }
--   </pre>
err402 :: ServantErr

-- | <a>err403</a> Forbidden
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err403 { errBody = "Please login first." }
--   </pre>
err403 :: ServantErr

-- | <a>err404</a> Not Found
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err404 { errBody = "(╯°□°)╯︵ ┻━┻)." }
--   </pre>
err404 :: ServantErr

-- | <a>err405</a> Method Not Allowed
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err405 { errBody = "Your account privileges does not allow for this.  Please pay $$$." }
--   </pre>
err405 :: ServantErr

-- | <a>err406</a> Not Acceptable
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err406
--   </pre>
err406 :: ServantErr

-- | <a>err407</a> Proxy Authentication Required
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err407
--   </pre>
err407 :: ServantErr

-- | <a>err409</a> Conflict
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err409 { errBody = "Transaction conflicts with 59879cb56c7c159231eeacdd503d755f7e835f74" }
--   </pre>
err409 :: ServantErr

-- | <a>err410</a> Gone
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err410 { errBody = "I know it was here at some point, but.. I blame bad luck." }
--   </pre>
err410 :: ServantErr

-- | <a>err411</a> Length Required
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError err411
--   </pre>
err411 :: ServantErr

-- | <a>err412</a> Precondition Failed
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err412 { errBody = "Precondition fail: x &lt; 42 &amp;&amp; y &gt; 57" }
--   </pre>
err412 :: ServantErr

-- | <a>err413</a> Request Entity Too Large
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err413 { errBody = "Request exceeded 64k." }
--   </pre>
err413 :: ServantErr

-- | <a>err414</a> Request-URI Too Large
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err414 { errBody = "Maximum length is 64." }
--   </pre>
err414 :: ServantErr

-- | <a>err415</a> Unsupported Media Type
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err415 { errBody = "Supported media types:  gif, png" }
--   </pre>
err415 :: ServantErr

-- | <a>err416</a> Request range not satisfiable
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err416 { errBody = "Valid range is [0, 424242]." }
--   </pre>
err416 :: ServantErr

-- | <a>err417</a> Expectation Failed
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err417 { errBody = "I found a quux in the request.  This isn't going to work." }
--   </pre>
err417 :: ServantErr

-- | <a>err500</a> Internal Server Error
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err500 { errBody = "Exception in module A.B.C:55.  Have a great day!" }
--   </pre>
err500 :: ServantErr

-- | <a>err501</a> Not Implemented
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err501 { errBody = "/v1/foo is not supported with quux in the request." }
--   </pre>
err501 :: ServantErr

-- | <a>err502</a> Bad Gateway
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err502 { errBody = "Tried gateway foo, bar, and baz.  None responded." }
--   </pre>
err502 :: ServantErr

-- | <a>err503</a> Service Unavailable
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err503 { errBody = "We're rewriting in PHP." }
--   </pre>
err503 :: ServantErr

-- | <a>err504</a> Gateway Time-out
--   
--   Example:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err504 { errBody = "Backend foobar did not respond in 5 seconds." }
--   </pre>
err504 :: ServantErr

-- | <a>err505</a> HTTP Version not supported
--   
--   Example usage:
--   
--   <pre>
--   failingHandler :: Handler ()
--   failingHandler = throwError $ err505 { errBody = "I support HTTP/4.0 only." }
--   </pre>
err505 :: ServantErr

-- | The WAI application.
--   
--   Note that, since WAI 3.0, this type is structured in continuation
--   passing style to allow for proper safe resource handling. This was
--   handled in the past via other means (e.g., <tt>ResourceT</tt>). As a
--   demonstration:
--   
--   <pre>
--   app :: Application
--   app req respond = bracket_
--       (putStrLn "Allocating scarce resource")
--       (putStrLn "Cleaning up")
--       (respond $ responseLBS status200 [] "Hello World")
--   </pre>
type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived


-- | This module defines a sever-side handler that lets you serve static
--   files.
--   
--   <ul>
--   <li><a>serveDirectory</a> lets you serve anything that lives under a
--   particular directory on your filesystem.</li>
--   </ul>
module Servant.Utils.StaticFiles

-- | Serve anything under the specified directory as a <a>Raw</a> endpoint.
--   
--   <pre>
--   type MyApi = "static" :&gt; Raw
--   
--   server :: Server MyApi
--   server = serveDirectory "/var/www"
--   </pre>
--   
--   would capture any request to <tt>/static/&lt;something&gt;</tt> and
--   look for <tt>&lt;something&gt;</tt> under <tt>/var/www</tt>.
--   
--   It will do its best to guess the MIME type for that file, based on the
--   extension, and send an appropriate <i>Content-Type</i> header if
--   possible.
--   
--   If your goal is to serve HTML, CSS and Javascript files that use the
--   rest of the API as a webapp backend, you will most likely not want the
--   static files to be hidden behind a <i>/static/</i> prefix. In that
--   case, remember to put the <a>serveDirectory</a> handler in the last
--   position, because <i>servant</i> will try to match the handlers in
--   order.
serveDirectory :: FilePath -> Server Raw

module Servant

-- | A concrete, poly-kinded proxy type
data Proxy k (t :: k) :: forall k. k -> *
Proxy :: Proxy k

-- | Is used within a monadic computation to begin exception processing.
throwError :: MonadError e m => forall a. e -> m a

module Servant.Server.Experimental.Auth

-- | Specify the type of data returned after we've authenticated a request.
--   quite often this is some <tt>User</tt> datatype.
--   
--   NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE

-- | Handlers for AuthProtected resources
--   
--   NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
newtype AuthHandler r usr
AuthHandler :: (r -> Handler usr) -> AuthHandler r usr
[unAuthHandler] :: AuthHandler r usr -> r -> Handler usr

-- | NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
mkAuthHandler :: (r -> Handler usr) -> AuthHandler r usr

-- | Known orphan instance.
instance GHC.Generics.Generic (Servant.Server.Experimental.Auth.AuthHandler r usr)
instance forall k1 k (api :: k1) (context :: [*]) (tag :: k). (Servant.Server.Internal.HasServer api context, Servant.Server.Internal.Context.HasContextEntry context (Servant.Server.Experimental.Auth.AuthHandler Network.Wai.Internal.Request (Servant.Server.Experimental.Auth.AuthServerData (Servant.API.Experimental.Auth.AuthProtect tag)))) => Servant.Server.Internal.HasServer (Servant.API.Experimental.Auth.AuthProtect tag Servant.API.Sub.:> api) context