lisette-stdlib 0.1.13

Little language inspired by Rust that compiles to Go
Documentation
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
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
// Generated by Lisette bindgen
// Source: net/http (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.12

import "go:bufio"
import "go:context"
import "go:crypto/tls"
import "go:io"
import "go:io/fs"
import "go:log"
import "go:mime/multipart"
import "go:net"
import "go:net/url"
import "go:time"

pub fn AllowQuerySemicolons(h: Handler) -> Handler

/// CanonicalHeaderKey returns the canonical format of the
/// header key s. The canonicalization converts the first
/// letter and any letter following a hyphen to upper case;
/// the rest are converted to lowercase. For example, the
/// canonical key for "accept-encoding" is "Accept-Encoding".
/// If s contains a space or invalid header field bytes, it is
/// returned without modifications.
pub fn CanonicalHeaderKey(s: string) -> string

/// DetectContentType implements the algorithm described
/// at https://mimesniff.spec.whatwg.org/ to determine the
/// Content-Type of the given data. It considers at most the
/// first 512 bytes of data. DetectContentType always returns
/// a valid MIME type: if it cannot determine a more specific one, it
/// returns "application/octet-stream".
pub fn DetectContentType(data: Slice<uint8>) -> string

/// Error replies to the request with the specified error message and HTTP code.
/// It does not otherwise end the request; the caller should ensure no further
/// writes are done to w.
/// The error message should be plain text.
/// 
/// Error deletes the Content-Length header,
/// sets Content-Type to “text/plain; charset=utf-8”,
/// and sets X-Content-Type-Options to “nosniff”.
/// This configures the header properly for the error message,
/// in case the caller had set it up expecting a successful output.
pub fn Error(w: ResponseWriter, error: string, code: int)

pub fn FS(fsys: fs.FS) -> FileSystem

pub fn FileServer(root: FileSystem) -> Handler

pub fn FileServerFS(root: fs.FS) -> Handler

/// Get issues a GET to the specified URL. If the response is one of
/// the following redirect codes, Get follows the redirect, up to a
/// maximum of 10 redirects:
/// 
/// 	301 (Moved Permanently)
/// 	302 (Found)
/// 	303 (See Other)
/// 	307 (Temporary Redirect)
/// 	308 (Permanent Redirect)
/// 
/// An error is returned if there were too many redirects or if there
/// was an HTTP protocol error. A non-2xx response doesn't cause an
/// error. Any returned error will be of type [*url.Error]. The url.Error
/// value's Timeout method will report true if the request timed out.
/// 
/// When err is nil, resp always contains a non-nil resp.Body.
/// Caller should close resp.Body when done reading from it.
/// 
/// Get is a wrapper around DefaultClient.Get.
/// 
/// To make a request with custom headers, use [NewRequest] and
/// DefaultClient.Do.
/// 
/// To make a request with a specified context.Context, use [NewRequestWithContext]
/// and DefaultClient.Do.
pub fn Get(url: string) -> Result<Ref<Response>, error>

/// Handle registers the handler for the given pattern in [DefaultServeMux].
/// The documentation for [ServeMux] explains how patterns are matched.
pub fn Handle(pattern: string, handler: Handler)

/// HandleFunc registers the handler function for the given pattern in [DefaultServeMux].
/// The documentation for [ServeMux] explains how patterns are matched.
pub fn HandleFunc(
  pattern: string,
  handler: fn(ResponseWriter, Ref<Request>) -> (),
)

/// Head issues a HEAD to the specified URL. If the response is one of
/// the following redirect codes, Head follows the redirect, up to a
/// maximum of 10 redirects:
/// 
/// 	301 (Moved Permanently)
/// 	302 (Found)
/// 	303 (See Other)
/// 	307 (Temporary Redirect)
/// 	308 (Permanent Redirect)
/// 
/// Head is a wrapper around DefaultClient.Head.
/// 
/// To make a request with a specified [context.Context], use [NewRequestWithContext]
/// and DefaultClient.Do.
pub fn Head(url: string) -> Result<Ref<Response>, error>

/// ListenAndServe listens on the TCP network address addr and then calls
/// [Serve] with handler to handle requests on incoming connections.
/// Accepted connections are configured to enable TCP keep-alives.
/// 
/// The handler is typically nil, in which case [DefaultServeMux] is used.
/// 
/// ListenAndServe always returns a non-nil error.
pub fn ListenAndServe(addr: string, handler: Handler) -> Result<(), error>

/// ListenAndServeTLS acts identically to [ListenAndServe], except that it
/// expects HTTPS connections. Additionally, files containing a certificate and
/// matching private key for the server must be provided. If the certificate
/// is signed by a certificate authority, the certFile should be the concatenation
/// of the server's certificate, any intermediates, and the CA's certificate.
pub fn ListenAndServeTLS(
  addr: string,
  certFile: string,
  keyFile: string,
  handler: Handler,
) -> Result<(), error>

pub fn MaxBytesHandler(h: Handler, n: int64) -> Handler

/// MaxBytesReader is similar to [io.LimitReader] but is intended for
/// limiting the size of incoming request bodies. In contrast to
/// io.LimitReader, MaxBytesReader's result is a ReadCloser, returns a
/// non-nil error of type [*MaxBytesError] for a Read beyond the limit,
/// and closes the underlying reader when its Close method is called.
/// 
/// MaxBytesReader prevents clients from accidentally or maliciously
/// sending a large request and wasting server resources. If possible,
/// it tells the [ResponseWriter] to close the connection after the limit
/// has been reached.
pub fn MaxBytesReader(w: ResponseWriter, r: io.ReadCloser, n: int64) -> io.ReadCloser

pub fn NewCrossOriginProtection() -> Ref<CrossOriginProtection>

pub fn NewFileTransport(fs: FileSystem) -> RoundTripper

pub fn NewFileTransportFS(fsys: fs.FS) -> RoundTripper

/// NewRequest wraps [NewRequestWithContext] using [context.Background].
pub fn NewRequest(method: string, url: string, body: io.Reader) -> Result<Ref<Request>, error>

/// NewRequestWithContext returns a new [Request] given a method, URL, and
/// optional body.
/// 
/// If the provided body is also an [io.Closer], the returned
/// [Request.Body] is set to body and will be closed (possibly
/// asynchronously) by the Client methods Do, Post, and PostForm,
/// and [Transport.RoundTrip].
/// 
/// NewRequestWithContext returns a Request suitable for use with
/// [Client.Do] or [Transport.RoundTrip]. To create a request for use with
/// testing a Server Handler, either use the [net/http/httptest.NewRequest] function,
/// use [ReadRequest], or manually update the Request fields.
/// For an outgoing client request, the context
/// controls the entire lifetime of a request and its response:
/// obtaining a connection, sending the request, and reading the
/// response headers and body. See the [Request] type's documentation for
/// the difference between inbound and outbound request fields.
/// 
/// If body is of type [*bytes.Buffer], [*bytes.Reader], or
/// [*strings.Reader], the returned request's ContentLength is set to its
/// exact value (instead of -1), GetBody is populated (so 307 and 308
/// redirects can replay the body), and Body is set to [NoBody] if the
/// ContentLength is 0.
pub fn NewRequestWithContext(
  ctx: context.Context,
  method: string,
  url: string,
  body: io.Reader,
) -> Result<Ref<Request>, error>

pub fn NewResponseController(rw: ResponseWriter) -> Ref<ResponseController>

pub fn NewServeMux() -> Ref<ServeMux>

/// NotFound replies to the request with an HTTP 404 not found error.
pub fn NotFound(w: ResponseWriter, r: Ref<Request>)

pub fn NotFoundHandler() -> Handler

/// ParseCookie parses a Cookie header value and returns all the cookies
/// which were set in it. Since the same cookie name can appear multiple times
/// the returned Values can contain more than one value for a given key.
pub fn ParseCookie(line: string) -> Result<Slice<Ref<Cookie>>, error>

/// ParseHTTPVersion parses an HTTP version string according to RFC 7230, section 2.6.
/// "HTTP/1.0" returns (1, 0, true). Note that strings without
/// a minor version, such as "HTTP/2", are not valid.
pub fn ParseHTTPVersion(vers: string) -> Option<(int, int)>

/// ParseSetCookie parses a Set-Cookie header value and returns a cookie.
/// It returns an error on syntax error.
pub fn ParseSetCookie(line: string) -> Result<Ref<Cookie>, error>

/// ParseTime parses a time header (such as the Date: header),
/// trying each of the three formats allowed by HTTP/1.1:
/// [TimeFormat], [time.RFC850], and [time.ANSIC].
pub fn ParseTime(text: string) -> Result<time.Time, error>

/// Post issues a POST to the specified URL.
/// 
/// Caller should close resp.Body when done reading from it.
/// 
/// If the provided body is an [io.Closer], it is closed after the
/// request.
/// 
/// Post is a wrapper around DefaultClient.Post.
/// 
/// To set custom headers, use [NewRequest] and DefaultClient.Do.
/// 
/// See the [Client.Do] method documentation for details on how redirects
/// are handled.
/// 
/// To make a request with a specified context.Context, use [NewRequestWithContext]
/// and DefaultClient.Do.
pub fn Post(url: string, contentType: string, body: io.Reader) -> Result<Ref<Response>, error>

/// PostForm issues a POST to the specified URL, with data's keys and
/// values URL-encoded as the request body.
/// 
/// The Content-Type header is set to application/x-www-form-urlencoded.
/// To set other headers, use [NewRequest] and DefaultClient.Do.
/// 
/// When err is nil, resp always contains a non-nil resp.Body.
/// Caller should close resp.Body when done reading from it.
/// 
/// PostForm is a wrapper around DefaultClient.PostForm.
/// 
/// See the [Client.Do] method documentation for details on how redirects
/// are handled.
/// 
/// To make a request with a specified [context.Context], use [NewRequestWithContext]
/// and DefaultClient.Do.
pub fn PostForm(url: string, data: url.Values) -> Result<Ref<Response>, error>

/// ProxyFromEnvironment returns the URL of the proxy to use for a
/// given request, as indicated by the environment variables
/// HTTP_PROXY, HTTPS_PROXY and NO_PROXY (or the lowercase versions
/// thereof). Requests use the proxy from the environment variable
/// matching their scheme, unless excluded by NO_PROXY.
/// 
/// The environment values may be either a complete URL or a
/// "host[:port]", in which case the "http" scheme is assumed.
/// An error is returned if the value is a different form.
/// 
/// A nil URL and nil error are returned if no proxy is defined in the
/// environment, or a proxy should not be used for the given request,
/// as defined by NO_PROXY.
/// 
/// As a special case, if req.URL.Host is "localhost" (with or without
/// a port number), then a nil URL and nil error will be returned.
pub fn ProxyFromEnvironment(req: Ref<Request>) -> Result<Ref<url.URL>, error>

/// ProxyURL returns a proxy function (for use in a [Transport])
/// that always returns the same URL.
pub fn ProxyURL(fixedURL: Ref<url.URL>) -> Option<fn(Ref<Request>) -> Result<Ref<url.URL>, error>>

/// ReadRequest reads and parses an incoming request from b.
/// 
/// ReadRequest is a low-level function and should only be used for
/// specialized applications; most code should use the [Server] to read
/// requests and handle them via the [Handler] interface. ReadRequest
/// only supports HTTP/1.x requests. For HTTP/2, use golang.org/x/net/http2.
pub fn ReadRequest(b: Ref<bufio.Reader>) -> Result<Ref<Request>, error>

/// ReadResponse reads and returns an HTTP response from r.
/// The req parameter optionally specifies the [Request] that corresponds
/// to this [Response]. If nil, a GET request is assumed.
/// Clients must call resp.Body.Close when finished reading resp.Body.
/// After that call, clients can inspect resp.Trailer to find key/value
/// pairs included in the response trailer.
pub fn ReadResponse(r: Ref<bufio.Reader>, req: Ref<Request>) -> Result<Ref<Response>, error>

/// Redirect replies to the request with a redirect to url,
/// which may be a path relative to the request path.
/// Any non-ASCII characters in url will be percent-encoded,
/// but existing percent encodings will not be changed.
/// 
/// The provided code should be in the 3xx range and is usually
/// [StatusMovedPermanently], [StatusFound] or [StatusSeeOther].
/// 
/// If the Content-Type header has not been set, [Redirect] sets it
/// to "text/html; charset=utf-8" and writes a small HTML body.
/// Setting the Content-Type header to any value, including nil,
/// disables that behavior.
pub fn Redirect(w: ResponseWriter, r: Ref<Request>, url: string, code: int)

pub fn RedirectHandler(url: string, code: int) -> Handler

/// Serve accepts incoming HTTP connections on the listener l,
/// creating a new service goroutine for each. The service goroutines
/// read requests and then call handler to reply to them.
/// 
/// The handler is typically nil, in which case [DefaultServeMux] is used.
/// 
/// HTTP/2 support is only enabled if the Listener returns [*tls.Conn]
/// connections and they were configured with "h2" in the TLS
/// Config.NextProtos.
/// 
/// Serve always returns a non-nil error.
pub fn Serve(l: net.Listener, handler: Handler) -> Result<(), error>

/// ServeContent replies to the request using the content in the
/// provided ReadSeeker. The main benefit of ServeContent over [io.Copy]
/// is that it handles Range requests properly, sets the MIME type, and
/// handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since,
/// and If-Range requests.
/// 
/// If the response's Content-Type header is not set, ServeContent
/// first tries to deduce the type from name's file extension and,
/// if that fails, falls back to reading the first block of the content
/// and passing it to [DetectContentType].
/// The name is otherwise unused; in particular it can be empty and is
/// never sent in the response.
/// 
/// If modtime is not the zero time or Unix epoch, ServeContent
/// includes it in a Last-Modified header in the response. If the
/// request includes an If-Modified-Since header, ServeContent uses
/// modtime to decide whether the content needs to be sent at all.
/// 
/// The content's Seek method must work: ServeContent uses
/// a seek to the end of the content to determine its size.
/// Note that [*os.File] implements the [io.ReadSeeker] interface.
/// 
/// If the caller has set w's ETag header formatted per RFC 7232, section 2.3,
/// ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.
/// 
/// If an error occurs when serving the request (for example, when
/// handling an invalid range request), ServeContent responds with an
/// error message. By default, ServeContent strips the Cache-Control,
/// Content-Encoding, ETag, and Last-Modified headers from error responses.
/// The GODEBUG setting httpservecontentkeepheaders=1 causes ServeContent
/// to preserve these headers.
pub fn ServeContent(
  w: ResponseWriter,
  req: Ref<Request>,
  name: string,
  modtime: time.Time,
  content: io.ReadSeeker,
)

/// ServeFile replies to the request with the contents of the named
/// file or directory.
/// 
/// If the provided file or directory name is a relative path, it is
/// interpreted relative to the current directory and may ascend to
/// parent directories. If the provided name is constructed from user
/// input, it should be sanitized before calling [ServeFile].
/// 
/// As a precaution, ServeFile will reject requests where r.URL.Path
/// contains a ".." path element; this protects against callers who
/// might unsafely use [filepath.Join] on r.URL.Path without sanitizing
/// it and then use that filepath.Join result as the name argument.
/// 
/// As another special case, ServeFile redirects any request where r.URL.Path
/// ends in "/index.html" to the same path, without the final
/// "index.html". To avoid such redirects either modify the path or
/// use [ServeContent].
/// 
/// Outside of those two special cases, ServeFile does not use
/// r.URL.Path for selecting the file or directory to serve; only the
/// file or directory provided in the name argument is used.
pub fn ServeFile(w: ResponseWriter, r: Ref<Request>, name: string)

/// ServeFileFS replies to the request with the contents
/// of the named file or directory from the file system fsys.
/// The files provided by fsys must implement [io.Seeker].
/// 
/// If the provided name is constructed from user input, it should be
/// sanitized before calling [ServeFileFS].
/// 
/// As a precaution, ServeFileFS will reject requests where r.URL.Path
/// contains a ".." path element; this protects against callers who
/// might unsafely use [filepath.Join] on r.URL.Path without sanitizing
/// it and then use that filepath.Join result as the name argument.
/// 
/// As another special case, ServeFileFS redirects any request where r.URL.Path
/// ends in "/index.html" to the same path, without the final
/// "index.html". To avoid such redirects either modify the path or
/// use [ServeContent].
/// 
/// Outside of those two special cases, ServeFileFS does not use
/// r.URL.Path for selecting the file or directory to serve; only the
/// file or directory provided in the name argument is used.
pub fn ServeFileFS(
  w: ResponseWriter,
  r: Ref<Request>,
  fsys: fs.FS,
  name: string,
)

/// ServeTLS accepts incoming HTTPS connections on the listener l,
/// creating a new service goroutine for each. The service goroutines
/// read requests and then call handler to reply to them.
/// 
/// The handler is typically nil, in which case [DefaultServeMux] is used.
/// 
/// Additionally, files containing a certificate and matching private key
/// for the server must be provided. If the certificate is signed by a
/// certificate authority, the certFile should be the concatenation
/// of the server's certificate, any intermediates, and the CA's certificate.
/// 
/// ServeTLS always returns a non-nil error.
pub fn ServeTLS(
  l: net.Listener,
  handler: Handler,
  certFile: string,
  keyFile: string,
) -> Result<(), error>

/// SetCookie adds a Set-Cookie header to the provided [ResponseWriter]'s headers.
/// The provided cookie must have a valid Name. Invalid cookies may be
/// silently dropped.
pub fn SetCookie(w: ResponseWriter, cookie: Ref<Cookie>)

/// StatusText returns a text for the HTTP status code. It returns the empty
/// string if the code is unknown.
pub fn StatusText(code: int) -> string

pub fn StripPrefix(prefix: string, h: Handler) -> Handler

pub fn TimeoutHandler(h: Handler, dt: time.Duration, msg: string) -> Handler

/// A Client is an HTTP client. Its zero value ([DefaultClient]) is a
/// usable client that uses [DefaultTransport].
/// 
/// The [Client.Transport] typically has internal state (cached TCP
/// connections), so Clients should be reused instead of created as
/// needed. Clients are safe for concurrent use by multiple goroutines.
/// 
/// A Client is higher-level than a [RoundTripper] (such as [Transport])
/// and additionally handles HTTP details such as cookies and
/// redirects.
/// 
/// When following redirects, the Client will forward all headers set on the
/// initial [Request] except:
/// 
///   - when forwarding sensitive headers like "Authorization",
///     "WWW-Authenticate", and "Cookie" to untrusted targets.
///     These headers will be ignored when following a redirect to a domain
///     that is not a subdomain match or exact match of the initial domain.
///     For example, a redirect from "foo.com" to either "foo.com" or "sub.foo.com"
///     will forward the sensitive headers, but a redirect to "bar.com" will not.
///   - when forwarding the "Cookie" header with a non-nil cookie Jar.
///     Since each redirect may mutate the state of the cookie jar,
///     a redirect may possibly alter a cookie set in the initial request.
///     When forwarding the "Cookie" header, any mutated cookies will be omitted,
///     with the expectation that the Jar will insert those mutated cookies
///     with the updated values (assuming the origin matches).
///     If Jar is nil, the initial cookies are forwarded without change.
pub struct Client {
  pub Transport: Option<RoundTripper>,
  pub CheckRedirect: fn(Ref<Request>, Slice<Ref<Request>>) -> Result<(), error>,
  pub Jar: Option<CookieJar>,
  pub Timeout: time.Duration,
}

/// The CloseNotifier interface is implemented by ResponseWriters which
/// allow detecting when the underlying connection has gone away.
/// 
/// This mechanism can be used to cancel long operations on the server
/// if the client has disconnected before the response is ready.
/// 
/// Deprecated: the CloseNotifier interface predates Go's context package.
/// New code should use [Request.Context] instead.
pub interface CloseNotifier {
  fn CloseNotify() -> Receiver<bool>
}

/// A ConnState represents the state of a client connection to a server.
/// It's used by the optional [Server.ConnState] hook.
pub struct ConnState(int)

/// A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an
/// HTTP response or the Cookie header of an HTTP request.
/// 
/// See https://tools.ietf.org/html/rfc6265 for details.
pub struct Cookie {
  pub Name: string,
  pub Value: string,
  pub Quoted: bool,
  pub Path: string,
  pub Domain: string,
  pub Expires: time.Time,
  pub RawExpires: string,
  pub MaxAge: int,
  pub Secure: bool,
  pub HttpOnly: bool,
  pub SameSite: SameSite,
  pub Partitioned: bool,
  pub Raw: string,
  pub Unparsed: Slice<string>,
}

/// A CookieJar manages storage and use of cookies in HTTP requests.
/// 
/// Implementations of CookieJar must be safe for concurrent use by multiple
/// goroutines.
/// 
/// The net/http/cookiejar package provides a CookieJar implementation.
pub interface CookieJar {
  fn Cookies(u: Ref<url.URL>) -> Slice<Ref<Cookie>>
  fn SetCookies(u: Ref<url.URL>, cookies: Slice<Ref<Cookie>>)
}

/// CrossOriginProtection implements protections against [Cross-Site Request
/// Forgery (CSRF)] by rejecting non-safe cross-origin browser requests.
/// 
/// Cross-origin requests are currently detected with the [Sec-Fetch-Site]
/// header, available in all browsers since 2023, or by comparing the hostname of
/// the [Origin] header with the Host header.
/// 
/// The GET, HEAD, and OPTIONS methods are [safe methods] and are always allowed.
/// It's important that applications do not perform any state changing actions
/// due to requests with safe methods.
/// 
/// Requests without Sec-Fetch-Site or Origin headers are currently assumed to be
/// either same-origin or non-browser requests, and are allowed.
/// 
/// The zero value of CrossOriginProtection is valid and has no trusted origins
/// or bypass patterns.
/// 
/// [Sec-Fetch-Site]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Site
/// [Origin]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin
/// [Cross-Site Request Forgery (CSRF)]: https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/CSRF
/// [safe methods]: https://developer.mozilla.org/en-US/docs/Glossary/Safe/HTTP
pub type CrossOriginProtection

/// A Dir implements [FileSystem] using the native file system restricted to a
/// specific directory tree.
/// 
/// While the [FileSystem.Open] method takes '/'-separated paths, a Dir's string
/// value is a directory path on the native file system, not a URL, so it is separated
/// by [filepath.Separator], which isn't necessarily '/'.
/// 
/// Note that Dir could expose sensitive files and directories. Dir will follow
/// symlinks pointing out of the directory tree, which can be especially dangerous
/// if serving from a directory in which users are able to create arbitrary symlinks.
/// Dir will also allow access to files and directories starting with a period,
/// which could expose sensitive directories like .git or sensitive files like
/// .htpasswd. To exclude files with a leading period, remove the files/directories
/// from the server or create a custom FileSystem implementation.
/// 
/// An empty Dir is treated as ".".
pub struct Dir(string)

/// A File is returned by a [FileSystem]'s Open method and can be
/// served by the [FileServer] implementation.
/// 
/// The methods should behave the same as those on an [*os.File].
pub interface File {
  fn Close() -> Result<(), error>
  fn Read(mut p: Slice<uint8>) -> Partial<int, error>
  fn Readdir(count: int) -> Result<Slice<fs.FileInfo>, error>
  fn Seek(offset: int64, whence: int) -> Result<int64, error>
  fn Stat() -> Result<fs.FileInfo, error>
}

/// A FileSystem implements access to a collection of named files.
/// The elements in a file path are separated by slash ('/', U+002F)
/// characters, regardless of host operating system convention.
/// See the [FileServer] function to convert a FileSystem to a [Handler].
/// 
/// This interface predates the [fs.FS] interface, which can be used instead:
/// the [FS] adapter function converts an fs.FS to a FileSystem.
pub interface FileSystem {
  fn Open(name: string) -> Result<File, error>
}

/// The Flusher interface is implemented by ResponseWriters that allow
/// an HTTP handler to flush buffered data to the client.
/// 
/// The default HTTP/1.x and HTTP/2 [ResponseWriter] implementations
/// support [Flusher], but ResponseWriter wrappers may not. Handlers
/// should always test for this ability at runtime.
/// 
/// Note that even for ResponseWriters that support Flush,
/// if the client is connected through an HTTP proxy,
/// the buffered data may not reach the client until the response
/// completes.
pub interface Flusher {
  fn Flush()
}

/// HTTP2Config defines HTTP/2 configuration parameters common to
/// both [Transport] and [Server].
pub struct HTTP2Config {
  pub MaxConcurrentStreams: int,
  pub MaxDecoderHeaderTableSize: int,
  pub MaxEncoderHeaderTableSize: int,
  pub MaxReadFrameSize: int,
  pub MaxReceiveBufferPerConnection: int,
  pub MaxReceiveBufferPerStream: int,
  pub SendPingTimeout: time.Duration,
  pub PingTimeout: time.Duration,
  pub WriteByteTimeout: time.Duration,
  pub PermitProhibitedCipherSuites: bool,
  pub CountError: fn(string) -> (),
}

/// A Handler responds to an HTTP request.
/// 
/// [Handler.ServeHTTP] should write reply headers and data to the [ResponseWriter]
/// and then return. Returning signals that the request is finished; it
/// is not valid to use the [ResponseWriter] or read from the
/// [Request.Body] after or concurrently with the completion of the
/// ServeHTTP call.
/// 
/// Depending on the HTTP client software, HTTP protocol version, and
/// any intermediaries between the client and the Go server, it may not
/// be possible to read from the [Request.Body] after writing to the
/// [ResponseWriter]. Cautious handlers should read the [Request.Body]
/// first, and then reply.
/// 
/// Except for reading the body, handlers should not modify the
/// provided Request.
/// 
/// If ServeHTTP panics, the server (the caller of ServeHTTP) assumes
/// that the effect of the panic was isolated to the active request.
/// It recovers the panic, logs a stack trace to the server error log,
/// and either closes the network connection or sends an HTTP/2
/// RST_STREAM, depending on the HTTP protocol. To abort a handler so
/// the client sees an interrupted response but the server doesn't log
/// an error, panic with the value [ErrAbortHandler].
pub interface Handler {
  fn ServeHTTP(arg0: ResponseWriter, arg1: Ref<Request>)
}

/// The HandlerFunc type is an adapter to allow the use of
/// ordinary functions as HTTP handlers. If f is a function
/// with the appropriate signature, HandlerFunc(f) is a
/// [Handler] that calls f.
pub type HandlerFunc = fn(ResponseWriter, Ref<Request>) -> ()

/// A Header represents the key-value pairs in an HTTP header.
/// 
/// The keys should be in canonical form, as returned by
/// [CanonicalHeaderKey].
pub struct Header(Map<string, Slice<string>>)

/// The Hijacker interface is implemented by ResponseWriters that allow
/// an HTTP handler to take over the connection.
/// 
/// The default [ResponseWriter] for HTTP/1.x connections supports
/// Hijacker, but HTTP/2 connections intentionally do not.
/// ResponseWriter wrappers may also not support Hijacker. Handlers
/// should always test for this ability at runtime.
pub interface Hijacker {
  fn Hijack() -> Result<(net.Conn, Ref<bufio.ReadWriter>), error>
}

/// MaxBytesError is returned by [MaxBytesReader] when its read limit is exceeded.
pub struct MaxBytesError {
  pub Limit: int64,
}

/// ProtocolError represents an HTTP protocol error.
/// 
/// Deprecated: Not all errors in the http package related to protocol errors
/// are of type ProtocolError.
pub struct ProtocolError {
  pub ErrorString: string,
}

/// Protocols is a set of HTTP protocols.
/// The zero value is an empty set of protocols.
/// 
/// The supported protocols are:
/// 
///   - HTTP1 is the HTTP/1.0 and HTTP/1.1 protocols.
///     HTTP1 is supported on both unsecured TCP and secured TLS connections.
/// 
///   - HTTP2 is the HTTP/2 protcol over a TLS connection.
/// 
///   - UnencryptedHTTP2 is the HTTP/2 protocol over an unsecured TCP connection.
pub type Protocols

/// PushOptions describes options for [Pusher.Push].
pub struct PushOptions {
  pub Method: string,
  pub Header: Header,
}

/// Pusher is the interface implemented by ResponseWriters that support
/// HTTP/2 server push. For more background, see
/// https://tools.ietf.org/html/rfc7540#section-8.2.
pub interface Pusher {
  fn Push(target: string, opts: Ref<PushOptions>) -> Result<(), error>
}

/// A Request represents an HTTP request received by a server
/// or to be sent by a client.
/// 
/// The field semantics differ slightly between client and server
/// usage. In addition to the notes on the fields below, see the
/// documentation for [Request.Write] and [RoundTripper].
pub struct Request {
  pub Method: string,
  pub URL: Option<Ref<url.URL>>,
  pub Proto: string,
  pub ProtoMajor: int,
  pub ProtoMinor: int,
  pub Header: Header,
  pub Body: Option<io.ReadCloser>,
  pub GetBody: fn() -> Result<io.ReadCloser, error>,
  pub ContentLength: int64,
  pub TransferEncoding: Slice<string>,
  pub Close: bool,
  pub Host: string,
  pub Form: url.Values,
  pub PostForm: url.Values,
  pub MultipartForm: Option<Ref<multipart.Form>>,
  pub Trailer: Header,
  pub RemoteAddr: string,
  pub RequestURI: string,
  pub TLS: Option<Ref<tls.ConnectionState>>,
  pub Cancel: Receiver<()>,
  pub Response: Option<Ref<Response>>,
  pub Pattern: string,
}

/// Response represents the response from an HTTP request.
/// 
/// The [Client] and [Transport] return Responses from servers once
/// the response headers have been received. The response body
/// is streamed on demand as the Body field is read.
pub struct Response {
  pub Status: string,
  pub StatusCode: int,
  pub Proto: string,
  pub ProtoMajor: int,
  pub ProtoMinor: int,
  pub Header: Header,
  pub Body: Option<io.ReadCloser>,
  pub ContentLength: int64,
  pub TransferEncoding: Slice<string>,
  pub Close: bool,
  pub Uncompressed: bool,
  pub Trailer: Header,
  pub Request: Option<Ref<Request>>,
  pub TLS: Option<Ref<tls.ConnectionState>>,
}

/// A ResponseController is used by an HTTP handler to control the response.
/// 
/// A ResponseController may not be used after the [Handler.ServeHTTP] method has returned.
pub type ResponseController

/// A ResponseWriter interface is used by an HTTP handler to
/// construct an HTTP response.
/// 
/// A ResponseWriter may not be used after [Handler.ServeHTTP] has returned.
pub interface ResponseWriter {
  fn Header() -> Header
  fn Write(arg0: Slice<uint8>) -> Partial<int, error>
  fn WriteHeader(statusCode: int)
}

/// RoundTripper is an interface representing the ability to execute a
/// single HTTP transaction, obtaining the [Response] for a given [Request].
/// 
/// A RoundTripper must be safe for concurrent use by multiple
/// goroutines.
pub interface RoundTripper {
  fn RoundTrip(arg0: Ref<Request>) -> Result<Ref<Response>, error>
}

/// SameSite allows a server to define a cookie attribute making it impossible for
/// the browser to send this cookie along with cross-site requests. The main
/// goal is to mitigate the risk of cross-origin information leakage, and provide
/// some protection against cross-site request forgery attacks.
/// 
/// See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details.
pub struct SameSite(int)

/// ServeMux is an HTTP request multiplexer.
/// It matches the URL of each incoming request against a list of registered
/// patterns and calls the handler for the pattern that
/// most closely matches the URL.
/// 
/// # Patterns
/// 
/// Patterns can match the method, host and path of a request.
/// Some examples:
/// 
///   - "/index.html" matches the path "/index.html" for any host and method.
///   - "GET /static/" matches a GET request whose path begins with "/static/".
///   - "example.com/" matches any request to the host "example.com".
///   - "example.com/{$}" matches requests with host "example.com" and path "/".
///   - "/b/{bucket}/o/{objectname...}" matches paths whose first segment is "b"
///     and whose third segment is "o". The name "bucket" denotes the second
///     segment and "objectname" denotes the remainder of the path.
/// 
/// In general, a pattern looks like
/// 
/// 	[METHOD ][HOST]/[PATH]
/// 
/// All three parts are optional; "/" is a valid pattern.
/// If METHOD is present, it must be followed by at least one space or tab.
/// 
/// Literal (that is, non-wildcard) parts of a pattern match
/// the corresponding parts of a request case-sensitively.
/// 
/// A pattern with no method matches every method. A pattern
/// with the method GET matches both GET and HEAD requests.
/// Otherwise, the method must match exactly.
/// 
/// A pattern with no host matches every host.
/// A pattern with a host matches URLs on that host only.
/// 
/// A path can include wildcard segments of the form {NAME} or {NAME...}.
/// For example, "/b/{bucket}/o/{objectname...}".
/// The wildcard name must be a valid Go identifier.
/// Wildcards must be full path segments: they must be preceded by a slash and followed by
/// either a slash or the end of the string.
/// For example, "/b_{bucket}" is not a valid pattern.
/// 
/// Normally a wildcard matches only a single path segment,
/// ending at the next literal slash (not %2F) in the request URL.
/// But if the "..." is present, then the wildcard matches the remainder of the URL path, including slashes.
/// (Therefore it is invalid for a "..." wildcard to appear anywhere but at the end of a pattern.)
/// The match for a wildcard can be obtained by calling [Request.PathValue] with the wildcard's name.
/// A trailing slash in a path acts as an anonymous "..." wildcard.
/// 
/// The special wildcard {$} matches only the end of the URL.
/// For example, the pattern "/{$}" matches only the path "/",
/// whereas the pattern "/" matches every path.
/// 
/// For matching, both pattern paths and incoming request paths are unescaped segment by segment.
/// So, for example, the path "/a%2Fb/100%25" is treated as having two segments, "a/b" and "100%".
/// The pattern "/a%2fb/" matches it, but the pattern "/a/b/" does not.
/// 
/// # Precedence
/// 
/// If two or more patterns match a request, then the most specific pattern takes precedence.
/// A pattern P1 is more specific than P2 if P1 matches a strict subset of P2’s requests;
/// that is, if P2 matches all the requests of P1 and more.
/// If neither is more specific, then the patterns conflict.
/// There is one exception to this rule, for backwards compatibility:
/// if two patterns would otherwise conflict and one has a host while the other does not,
/// then the pattern with the host takes precedence.
/// If a pattern passed to [ServeMux.Handle] or [ServeMux.HandleFunc] conflicts with
/// another pattern that is already registered, those functions panic.
/// 
/// As an example of the general rule, "/images/thumbnails/" is more specific than "/images/",
/// so both can be registered.
/// The former matches paths beginning with "/images/thumbnails/"
/// and the latter will match any other path in the "/images/" subtree.
/// 
/// As another example, consider the patterns "GET /" and "/index.html":
/// both match a GET request for "/index.html", but the former pattern
/// matches all other GET and HEAD requests, while the latter matches any
/// request for "/index.html" that uses a different method.
/// The patterns conflict.
/// 
/// # Trailing-slash redirection
/// 
/// Consider a [ServeMux] with a handler for a subtree, registered using a trailing slash or "..." wildcard.
/// If the ServeMux receives a request for the subtree root without a trailing slash,
/// it redirects the request by adding the trailing slash.
/// This behavior can be overridden with a separate registration for the path without
/// the trailing slash or "..." wildcard. For example, registering "/images/" causes ServeMux
/// to redirect a request for "/images" to "/images/", unless "/images" has
/// been registered separately.
/// 
/// # Request sanitizing
/// 
/// ServeMux also takes care of sanitizing the URL request path and the Host
/// header, stripping the port number and redirecting any request containing . or
/// .. segments or repeated slashes to an equivalent, cleaner URL.
/// Escaped path elements such as "%2e" for "." and "%2f" for "/" are preserved
/// and aren't considered separators for request routing.
/// 
/// # Compatibility
/// 
/// The pattern syntax and matching behavior of ServeMux changed significantly
/// in Go 1.22. To restore the old behavior, set the GODEBUG environment variable
/// to "httpmuxgo121=1". This setting is read once, at program startup; changes
/// during execution will be ignored.
/// 
/// The backwards-incompatible changes include:
///   - Wildcards are just ordinary literal path segments in 1.21.
///     For example, the pattern "/{x}" will match only that path in 1.21,
///     but will match any one-segment path in 1.22.
///   - In 1.21, no pattern was rejected, unless it was empty or conflicted with an existing pattern.
///     In 1.22, syntactically invalid patterns will cause [ServeMux.Handle] and [ServeMux.HandleFunc] to panic.
///     For example, in 1.21, the patterns "/{"  and "/a{x}" match themselves,
///     but in 1.22 they are invalid and will cause a panic when registered.
///   - In 1.22, each segment of a pattern is unescaped; this was not done in 1.21.
///     For example, in 1.22 the pattern "/%61" matches the path "/a" ("%61" being the URL escape sequence for "a"),
///     but in 1.21 it would match only the path "/%2561" (where "%25" is the escape for the percent sign).
///   - When matching patterns to paths, in 1.22 each segment of the path is unescaped; in 1.21, the entire path is unescaped.
///     This change mostly affects how paths with %2F escapes adjacent to slashes are treated.
///     See https://go.dev/issue/21955 for details.
pub type ServeMux

/// A Server defines parameters for running an HTTP server.
/// The zero value for Server is a valid configuration.
pub struct Server {
  pub Addr: string,
  pub Handler: Option<Handler>,
  pub DisableGeneralOptionsHandler: bool,
  pub TLSConfig: Option<Ref<tls.Config>>,
  pub ReadTimeout: time.Duration,
  pub ReadHeaderTimeout: time.Duration,
  pub WriteTimeout: time.Duration,
  pub IdleTimeout: time.Duration,
  pub MaxHeaderBytes: int,
  pub TLSNextProto: Map<string, fn(Ref<Server>, Ref<tls.Conn>, Handler) -> ()>,
  pub ConnState: fn(net.Conn, ConnState) -> (),
  pub ErrorLog: Option<Ref<log.Logger>>,
  pub BaseContext: fn(net.Listener) -> context.Context,
  pub ConnContext: fn(context.Context, net.Conn) -> context.Context,
  pub HTTP2: Option<Ref<HTTP2Config>>,
  pub Protocols: Option<Ref<Protocols>>,
}

/// Transport is an implementation of [RoundTripper] that supports HTTP,
/// HTTPS, and HTTP proxies (for either HTTP or HTTPS with CONNECT).
/// 
/// By default, Transport caches connections for future re-use.
/// This may leave many open connections when accessing many hosts.
/// This behavior can be managed using [Transport.CloseIdleConnections] method
/// and the [Transport.MaxIdleConnsPerHost] and [Transport.DisableKeepAlives] fields.
/// 
/// Transports should be reused instead of created as needed.
/// Transports are safe for concurrent use by multiple goroutines.
/// 
/// A Transport is a low-level primitive for making HTTP and HTTPS requests.
/// For high-level functionality, such as cookies and redirects, see [Client].
/// 
/// Transport uses HTTP/1.1 for HTTP URLs and either HTTP/1.1 or HTTP/2
/// for HTTPS URLs, depending on whether the server supports HTTP/2,
/// and how the Transport is configured. The [DefaultTransport] supports HTTP/2.
/// To explicitly enable HTTP/2 on a transport, set [Transport.Protocols].
/// 
/// Responses with status codes in the 1xx range are either handled
/// automatically (100 expect-continue) or ignored. The one
/// exception is HTTP status code 101 (Switching Protocols), which is
/// considered a terminal status and returned by [Transport.RoundTrip]. To see the
/// ignored 1xx responses, use the httptrace trace package's
/// ClientTrace.Got1xxResponse.
/// 
/// Transport only retries a request upon encountering a network error
/// if the connection has been already been used successfully and if the
/// request is idempotent and either has no body or has its [Request.GetBody]
/// defined. HTTP requests are considered idempotent if they have HTTP methods
/// GET, HEAD, OPTIONS, or TRACE; or if their [Header] map contains an
/// "Idempotency-Key" or "X-Idempotency-Key" entry. If the idempotency key
/// value is a zero-length slice, the request is treated as idempotent but the
/// header is not sent on the wire.
pub struct Transport {
  pub Proxy: fn(Ref<Request>) -> Result<Ref<url.URL>, error>,
  pub OnProxyConnectResponse: fn(context.Context, Ref<url.URL>, Ref<Request>, Ref<Response>) -> Result<(), error>,
  pub DialContext: fn(context.Context, string, string) -> Result<net.Conn, error>,
  pub Dial: fn(string, string) -> Result<net.Conn, error>,
  pub DialTLSContext: fn(context.Context, string, string) -> Result<net.Conn, error>,
  pub DialTLS: fn(string, string) -> Result<net.Conn, error>,
  pub TLSClientConfig: Option<Ref<tls.Config>>,
  pub TLSHandshakeTimeout: time.Duration,
  pub DisableKeepAlives: bool,
  pub DisableCompression: bool,
  pub MaxIdleConns: int,
  pub MaxIdleConnsPerHost: int,
  pub MaxConnsPerHost: int,
  pub IdleConnTimeout: time.Duration,
  pub ResponseHeaderTimeout: time.Duration,
  pub ExpectContinueTimeout: time.Duration,
  pub TLSNextProto: Map<string, fn(string, Ref<tls.Conn>) -> RoundTripper>,
  pub ProxyConnectHeader: Header,
  pub GetProxyConnectHeader: fn(context.Context, Ref<url.URL>, string) -> Result<Header, error>,
  pub MaxResponseHeaderBytes: int64,
  pub WriteBufferSize: int,
  pub ReadBufferSize: int,
  pub ForceAttemptHTTP2: bool,
  pub HTTP2: Option<Ref<HTTP2Config>>,
  pub Protocols: Option<Ref<Protocols>>,
}

/// DefaultMaxHeaderBytes is the maximum permitted size of the headers
/// in an HTTP request.
/// This can be overridden by setting [Server.MaxHeaderBytes].
const DefaultMaxHeaderBytes = 1048576

/// DefaultMaxIdleConnsPerHost is the default value of [Transport]'s
/// MaxIdleConnsPerHost.
const DefaultMaxIdleConnsPerHost = 2

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodConnect = "CONNECT"

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodDelete = "DELETE"

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodGet = "GET"

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodHead = "HEAD"

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodOptions = "OPTIONS"

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodPatch = "PATCH"

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodPost = "POST"

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodPut = "PUT"

/// Common HTTP methods.
/// 
/// Unless otherwise noted, these are defined in RFC 7231 section 4.3.
const MethodTrace = "TRACE"

const SameSiteDefaultMode: SameSite = 1

const SameSiteLaxMode: SameSite = 2

const SameSiteNoneMode: SameSite = 4

const SameSiteStrictMode: SameSite = 3

const StateActive: ConnState = 1

const StateClosed: ConnState = 4

const StateHijacked: ConnState = 3

const StateIdle: ConnState = 2

const StateNew: ConnState = 0

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusAccepted = 202

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusAlreadyReported = 208

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusBadGateway = 502

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusBadRequest = 400

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusConflict = 409

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusContinue = 100

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusCreated = 201

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusEarlyHints = 103

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusExpectationFailed = 417

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusFailedDependency = 424

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusForbidden = 403

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusFound = 302

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusGatewayTimeout = 504

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusGone = 410

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusHTTPVersionNotSupported = 505

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusIMUsed = 226

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusInsufficientStorage = 507

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusInternalServerError = 500

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusLengthRequired = 411

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusLocked = 423

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusLoopDetected = 508

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusMethodNotAllowed = 405

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusMisdirectedRequest = 421

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusMovedPermanently = 301

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusMultiStatus = 207

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusMultipleChoices = 300

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusNetworkAuthenticationRequired = 511

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusNoContent = 204

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusNonAuthoritativeInfo = 203

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusNotAcceptable = 406

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusNotExtended = 510

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusNotFound = 404

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusNotImplemented = 501

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusNotModified = 304

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusOK = 200

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusPartialContent = 206

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusPaymentRequired = 402

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusPermanentRedirect = 308

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusPreconditionFailed = 412

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusPreconditionRequired = 428

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusProcessing = 102

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusProxyAuthRequired = 407

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusRequestEntityTooLarge = 413

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusRequestHeaderFieldsTooLarge = 431

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusRequestTimeout = 408

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusRequestURITooLong = 414

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusRequestedRangeNotSatisfiable = 416

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusResetContent = 205

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusSeeOther = 303

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusServiceUnavailable = 503

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusSwitchingProtocols = 101

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusTeapot = 418

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusTemporaryRedirect = 307

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusTooEarly = 425

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusTooManyRequests = 429

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusUnauthorized = 401

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusUnavailableForLegalReasons = 451

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusUnprocessableEntity = 422

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusUnsupportedMediaType = 415

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusUpgradeRequired = 426

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusUseProxy = 305

/// HTTP status codes as registered with IANA.
/// See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
const StatusVariantAlsoNegotiates = 506

/// TimeFormat is the time format to use when generating times in HTTP
/// headers. It is like [time.RFC1123] but hard-codes GMT as the time
/// zone. The time being formatted must be in UTC for Format to
/// generate the correct format.
/// 
/// For parsing this time format, see [ParseTime].
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"

/// TrailerPrefix is a magic prefix for [ResponseWriter.Header] map keys
/// that, if present, signals that the map entry is actually for
/// the response trailers, and not the response headers. The prefix
/// is stripped after the ServeHTTP call finishes and the values are
/// sent in the trailers.
/// 
/// This mechanism is intended only for trailers that are not known
/// prior to the headers being written. If the set of trailers is fixed
/// or known before the header is written, the normal Go trailers mechanism
/// is preferred:
/// 
/// 	https://pkg.go.dev/net/http#ResponseWriter
/// 	https://pkg.go.dev/net/http#example-ResponseWriter-Trailers
const TrailerPrefix = "Trailer:"

/// DefaultClient is the default [Client] and is used by [Get], [Head], and [Post].
pub var DefaultClient: Ref<Client>

/// DefaultServeMux is the default [ServeMux] used by [Serve].
pub var DefaultServeMux: Ref<ServeMux>

pub var DefaultTransport: RoundTripper

/// ErrAbortHandler is a sentinel panic value to abort a handler.
/// While any panic from ServeHTTP aborts the response to the client,
/// panicking with ErrAbortHandler also suppresses logging of a stack
/// trace to the server's error log.
pub var ErrAbortHandler: error

/// Errors used by the HTTP server.
pub var ErrBodyNotAllowed: error

/// ErrBodyReadAfterClose is returned when reading a [Request] or [Response]
/// Body after the body has been closed. This typically happens when the body is
/// read after an HTTP [Handler] calls WriteHeader or Write on its
/// [ResponseWriter].
pub var ErrBodyReadAfterClose: error

/// Errors used by the HTTP server.
pub var ErrContentLength: error

/// ErrHandlerTimeout is returned on [ResponseWriter] Write calls
/// in handlers which have timed out.
pub var ErrHandlerTimeout: error

pub var ErrHeaderTooLong: Ref<ProtocolError>

/// Errors used by the HTTP server.
pub var ErrHijacked: error

/// ErrLineTooLong is returned when reading request or response bodies
/// with malformed chunked encoding.
pub var ErrLineTooLong: error

pub var ErrMissingBoundary: Ref<ProtocolError>

pub var ErrMissingContentLength: Ref<ProtocolError>

/// ErrMissingFile is returned by FormFile when the provided file field name
/// is either not present in the request or not a file field.
pub var ErrMissingFile: error

/// ErrNoCookie is returned by Request's Cookie method when a cookie is not found.
pub var ErrNoCookie: error

/// ErrNoLocation is returned by the [Response.Location] method
/// when no Location header is present.
pub var ErrNoLocation: error

pub var ErrNotMultipart: Ref<ProtocolError>

pub var ErrNotSupported: Ref<ProtocolError>

/// ErrSchemeMismatch is returned when a server returns an HTTP response to an HTTPS client.
pub var ErrSchemeMismatch: error

/// ErrServerClosed is returned by the [Server.Serve], [ServeTLS], [ListenAndServe],
/// and [ListenAndServeTLS] methods after a call to [Server.Shutdown] or [Server.Close].
pub var ErrServerClosed: error

pub var ErrShortBody: Ref<ProtocolError>

/// ErrSkipAltProtocol is a sentinel error value defined by Transport.RegisterProtocol.
pub var ErrSkipAltProtocol: error

pub var ErrUnexpectedTrailer: Ref<ProtocolError>

/// ErrUseLastResponse can be returned by Client.CheckRedirect hooks to
/// control how redirects are processed. If returned, the next request
/// is not sent and the most recent response is returned with its body
/// unclosed.
pub var ErrUseLastResponse: error

/// Errors used by the HTTP server.
pub var ErrWriteAfterFlush: error

// SKIPPED: LocalAddrContextKey - anonymous-struct
// anonymous struct types are not supported

/// NoBody is an [io.ReadCloser] with no bytes. Read always returns EOF
/// and Close always returns nil. It can be used in an outgoing client
/// request to explicitly signal that a request has zero bytes.
/// An alternative, however, is to simply set [Request.Body] to nil.
pub var NoBody: ()

// SKIPPED: ServerContextKey - anonymous-struct
// anonymous struct types are not supported

impl Client {
  /// CloseIdleConnections closes any connections on its [Transport] which
  /// were previously connected from previous requests but are now
  /// sitting idle in a "keep-alive" state. It does not interrupt any
  /// connections currently in use.
  /// 
  /// If [Client.Transport] does not have a [Client.CloseIdleConnections] method
  /// then this method does nothing.
  fn CloseIdleConnections(self: Ref<Client>)

  /// Do sends an HTTP request and returns an HTTP response, following
  /// policy (such as redirects, cookies, auth) as configured on the
  /// client.
  /// 
  /// An error is returned if caused by client policy (such as
  /// CheckRedirect), or failure to speak HTTP (such as a network
  /// connectivity problem). A non-2xx status code doesn't cause an
  /// error.
  /// 
  /// If the returned error is nil, the [Response] will contain a non-nil
  /// Body which the user is expected to close. If the Body is not both
  /// read to EOF and closed, the [Client]'s underlying [RoundTripper]
  /// (typically [Transport]) may not be able to re-use a persistent TCP
  /// connection to the server for a subsequent "keep-alive" request.
  /// 
  /// The request Body, if non-nil, will be closed by the underlying
  /// Transport, even on errors. The Body may be closed asynchronously after
  /// Do returns.
  /// 
  /// On error, any Response can be ignored. A non-nil Response with a
  /// non-nil error only occurs when CheckRedirect fails, and even then
  /// the returned [Response.Body] is already closed.
  /// 
  /// Generally [Get], [Post], or [PostForm] will be used instead of Do.
  /// 
  /// If the server replies with a redirect, the Client first uses the
  /// CheckRedirect function to determine whether the redirect should be
  /// followed. If permitted, a 301, 302, or 303 redirect causes
  /// subsequent requests to use HTTP method GET
  /// (or HEAD if the original request was HEAD), with no body.
  /// A 307 or 308 redirect preserves the original HTTP method and body,
  /// provided that the [Request.GetBody] function is defined.
  /// The [NewRequest] function automatically sets GetBody for common
  /// standard library body types.
  /// 
  /// Any returned error will be of type [*url.Error]. The url.Error
  /// value's Timeout method will report true if the request timed out.
  fn Do(self: Ref<Client>, req: Ref<Request>) -> Result<Ref<Response>, error>

  /// Get issues a GET to the specified URL. If the response is one of the
  /// following redirect codes, Get follows the redirect after calling the
  /// [Client.CheckRedirect] function:
  /// 
  /// 	301 (Moved Permanently)
  /// 	302 (Found)
  /// 	303 (See Other)
  /// 	307 (Temporary Redirect)
  /// 	308 (Permanent Redirect)
  /// 
  /// An error is returned if the [Client.CheckRedirect] function fails
  /// or if there was an HTTP protocol error. A non-2xx response doesn't
  /// cause an error. Any returned error will be of type [*url.Error]. The
  /// url.Error value's Timeout method will report true if the request
  /// timed out.
  /// 
  /// When err is nil, resp always contains a non-nil resp.Body.
  /// Caller should close resp.Body when done reading from it.
  /// 
  /// To make a request with custom headers, use [NewRequest] and [Client.Do].
  /// 
  /// To make a request with a specified context.Context, use [NewRequestWithContext]
  /// and Client.Do.
  fn Get(self: Ref<Client>, url: string) -> Result<Ref<Response>, error>

  /// Head issues a HEAD to the specified URL. If the response is one of the
  /// following redirect codes, Head follows the redirect after calling the
  /// [Client.CheckRedirect] function:
  /// 
  /// 	301 (Moved Permanently)
  /// 	302 (Found)
  /// 	303 (See Other)
  /// 	307 (Temporary Redirect)
  /// 	308 (Permanent Redirect)
  /// 
  /// To make a request with a specified [context.Context], use [NewRequestWithContext]
  /// and [Client.Do].
  fn Head(self: Ref<Client>, url: string) -> Result<Ref<Response>, error>

  /// Post issues a POST to the specified URL.
  /// 
  /// Caller should close resp.Body when done reading from it.
  /// 
  /// If the provided body is an [io.Closer], it is closed after the
  /// request.
  /// 
  /// To set custom headers, use [NewRequest] and [Client.Do].
  /// 
  /// To make a request with a specified context.Context, use [NewRequestWithContext]
  /// and [Client.Do].
  /// 
  /// See the [Client.Do] method documentation for details on how redirects
  /// are handled.
  fn Post(self: Ref<Client>, url: string, contentType: string, body: io.Reader) -> Result<Ref<Response>, error>

  /// PostForm issues a POST to the specified URL,
  /// with data's keys and values URL-encoded as the request body.
  /// 
  /// The Content-Type header is set to application/x-www-form-urlencoded.
  /// To set other headers, use [NewRequest] and [Client.Do].
  /// 
  /// When err is nil, resp always contains a non-nil resp.Body.
  /// Caller should close resp.Body when done reading from it.
  /// 
  /// See the [Client.Do] method documentation for details on how redirects
  /// are handled.
  /// 
  /// To make a request with a specified context.Context, use [NewRequestWithContext]
  /// and Client.Do.
  fn PostForm(self: Ref<Client>, url: string, data: url.Values) -> Result<Ref<Response>, error>
}

impl ConnState {
  fn String(self) -> string
}

impl Cookie {
  /// String returns the serialization of the cookie for use in a [Cookie]
  /// header (if only Name and Value are set) or a Set-Cookie response
  /// header (if other fields are set).
  /// If c is nil or c.Name is invalid, the empty string is returned.
  fn String(self: Ref<Cookie>) -> string

  /// Valid reports whether the cookie is valid.
  fn Valid(self: Ref<Cookie>) -> Result<(), error>
}

impl CrossOriginProtection {
  /// AddInsecureBypassPattern permits all requests that match the given pattern.
  /// 
  /// The pattern syntax and precedence rules are the same as [ServeMux]. Only
  /// requests that match the pattern directly are permitted. Those that ServeMux
  /// would redirect to a pattern (e.g. after cleaning the path or adding a
  /// trailing slash) are not.
  /// 
  /// AddInsecureBypassPattern can be called concurrently with other methods or
  /// request handling, and applies to future requests.
  fn AddInsecureBypassPattern(self: Ref<CrossOriginProtection>, pattern: string)

  /// AddTrustedOrigin allows all requests with an [Origin] header
  /// which exactly matches the given value.
  /// 
  /// Origin header values are of the form "scheme://host[:port]".
  /// 
  /// AddTrustedOrigin can be called concurrently with other methods
  /// or request handling, and applies to future requests.
  /// 
  /// [Origin]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin
  fn AddTrustedOrigin(self: Ref<CrossOriginProtection>, origin: string) -> Result<(), error>

  /// Check applies cross-origin checks to a request.
  /// It returns an error if the request should be rejected.
  fn Check(self: Ref<CrossOriginProtection>, req: Ref<Request>) -> Result<(), error>

  /// Handler returns a handler that applies cross-origin checks
  /// before invoking the handler h.
  /// 
  /// If a request fails cross-origin checks, the request is rejected
  /// with a 403 Forbidden status or handled with the handler passed
  /// to [CrossOriginProtection.SetDenyHandler].
  fn Handler(self: Ref<CrossOriginProtection>, h: Handler) -> Handler

  /// SetDenyHandler sets a handler to invoke when a request is rejected.
  /// The default error handler responds with a 403 Forbidden status.
  /// 
  /// SetDenyHandler can be called concurrently with other methods
  /// or request handling, and applies to future requests.
  /// 
  /// Check does not call the error handler.
  fn SetDenyHandler(self: Ref<CrossOriginProtection>, h: Handler)
}

impl Dir {
  /// Open implements [FileSystem] using [os.Open], opening files for reading rooted
  /// and relative to the directory d.
  fn Open(self, name: string) -> Result<File, error>
}

impl HandlerFunc {
  /// ServeHTTP calls f(w, r).
  fn ServeHTTP(self, w: ResponseWriter, r: Ref<Request>)
}

impl Header {
  /// Add adds the key, value pair to the header.
  /// It appends to any existing values associated with key.
  /// The key is case insensitive; it is canonicalized by
  /// [CanonicalHeaderKey].
  fn Add(self, key: string, value: string)

  /// Clone returns a copy of h or nil if h is nil.
  fn Clone(self) -> Header

  /// Del deletes the values associated with key.
  /// The key is case insensitive; it is canonicalized by
  /// [CanonicalHeaderKey].
  fn Del(self, key: string)

  /// Get gets the first value associated with the given key. If
  /// there are no values associated with the key, Get returns "".
  /// It is case insensitive; [textproto.CanonicalMIMEHeaderKey] is
  /// used to canonicalize the provided key. Get assumes that all
  /// keys are stored in canonical form. To use non-canonical keys,
  /// access the map directly.
  fn Get(self, key: string) -> string

  /// Set sets the header entries associated with key to the
  /// single element value. It replaces any existing values
  /// associated with key. The key is case insensitive; it is
  /// canonicalized by [textproto.CanonicalMIMEHeaderKey].
  /// To use non-canonical keys, assign to the map directly.
  fn Set(self, key: string, value: string)

  /// Values returns all values associated with the given key.
  /// It is case insensitive; [textproto.CanonicalMIMEHeaderKey] is
  /// used to canonicalize the provided key. To use non-canonical
  /// keys, access the map directly.
  /// The returned slice is not a copy.
  fn Values(self, key: string) -> Slice<string>

  /// Write writes a header in wire format.
  fn Write(self, w: io.Writer) -> Result<(), error>

  /// WriteSubset writes a header in wire format.
  /// If exclude is not nil, keys where exclude[key] == true are not written.
  /// Keys are not canonicalized before checking the exclude map.
  fn WriteSubset(self, w: io.Writer, exclude: Map<string, bool>) -> Result<(), error>
}

impl MaxBytesError {
  fn Error(self: Ref<MaxBytesError>) -> string
}

impl ProtocolError {
  fn Error(self: Ref<ProtocolError>) -> string

  /// Is lets http.ErrNotSupported match errors.ErrUnsupported.
  fn Is(self: Ref<ProtocolError>, err: error) -> bool
}

impl Protocols {
  /// HTTP1 reports whether p includes HTTP/1.
  fn HTTP1(self) -> bool

  /// HTTP2 reports whether p includes HTTP/2.
  fn HTTP2(self) -> bool

  /// SetHTTP1 adds or removes HTTP/1 from p.
  fn SetHTTP1(self: Ref<Protocols>, ok: bool)

  /// SetHTTP2 adds or removes HTTP/2 from p.
  fn SetHTTP2(self: Ref<Protocols>, ok: bool)

  /// SetUnencryptedHTTP2 adds or removes unencrypted HTTP/2 from p.
  fn SetUnencryptedHTTP2(self: Ref<Protocols>, ok: bool)

  fn String(self) -> string

  /// UnencryptedHTTP2 reports whether p includes unencrypted HTTP/2.
  fn UnencryptedHTTP2(self) -> bool
}

impl Request {
  /// AddCookie adds a cookie to the request. Per RFC 6265 section 5.4,
  /// AddCookie does not attach more than one [Cookie] header field. That
  /// means all cookies, if any, are written into the same line,
  /// separated by semicolon.
  /// AddCookie only sanitizes c's name and value, and does not sanitize
  /// a Cookie header already present in the request.
  fn AddCookie(self: Ref<Request>, c: Ref<Cookie>)

  /// BasicAuth returns the username and password provided in the request's
  /// Authorization header, if the request uses HTTP Basic Authentication.
  /// See RFC 2617, Section 2.
  fn BasicAuth(self: Ref<Request>) -> Option<(string, string)>

  /// Clone returns a deep copy of r with its context changed to ctx.
  /// The provided ctx must be non-nil.
  /// 
  /// Clone only makes a shallow copy of the Body field.
  /// 
  /// For an outgoing client request, the context controls the entire
  /// lifetime of a request and its response: obtaining a connection,
  /// sending the request, and reading the response headers and body.
  fn Clone(self: Ref<Request>, ctx: context.Context) -> Ref<Request>

  /// Context returns the request's context. To change the context, use
  /// [Request.Clone] or [Request.WithContext].
  /// 
  /// The returned context is always non-nil; it defaults to the
  /// background context.
  /// 
  /// For outgoing client requests, the context controls cancellation.
  /// 
  /// For incoming server requests, the context is canceled when the
  /// client's connection closes, the request is canceled (with HTTP/2),
  /// or when the ServeHTTP method returns.
  fn Context(self: Ref<Request>) -> context.Context

  /// Cookie returns the named cookie provided in the request or
  /// [ErrNoCookie] if not found.
  /// If multiple cookies match the given name, only one cookie will
  /// be returned.
  fn Cookie(self: Ref<Request>, name: string) -> Result<Ref<Cookie>, error>

  /// Cookies parses and returns the HTTP cookies sent with the request.
  fn Cookies(self: Ref<Request>) -> Slice<Ref<Cookie>>

  /// CookiesNamed parses and returns the named HTTP cookies sent with the request
  /// or an empty slice if none matched.
  fn CookiesNamed(self: Ref<Request>, name: string) -> Slice<Ref<Cookie>>

  /// FormFile returns the first file for the provided form key.
  /// FormFile calls [Request.ParseMultipartForm] and [Request.ParseForm] if necessary.
  fn FormFile(self: Ref<Request>, key: string) -> Result<(multipart.File, Ref<multipart.FileHeader>), error>

  /// FormValue returns the first value for the named component of the query.
  /// The precedence order:
  ///  1. application/x-www-form-urlencoded form body (POST, PUT, PATCH only)
  ///  2. query parameters (always)
  ///  3. multipart/form-data form body (always)
  /// 
  /// FormValue calls [Request.ParseMultipartForm] and [Request.ParseForm]
  /// if necessary and ignores any errors returned by these functions.
  /// If key is not present, FormValue returns the empty string.
  /// To access multiple values of the same key, call ParseForm and
  /// then inspect [Request.Form] directly.
  fn FormValue(self: Ref<Request>, key: string) -> string

  /// MultipartReader returns a MIME multipart reader if this is a
  /// multipart/form-data or a multipart/mixed POST request, else returns nil and an error.
  /// Use this function instead of [Request.ParseMultipartForm] to
  /// process the request body as a stream.
  fn MultipartReader(self: Ref<Request>) -> Result<Ref<multipart.Reader>, error>

  /// ParseForm populates r.Form and r.PostForm.
  /// 
  /// For all requests, ParseForm parses the raw query from the URL and updates
  /// r.Form.
  /// 
  /// For POST, PUT, and PATCH requests, it also reads the request body, parses it
  /// as a form and puts the results into both r.PostForm and r.Form. Request body
  /// parameters take precedence over URL query string values in r.Form.
  /// 
  /// If the request Body's size has not already been limited by [MaxBytesReader],
  /// the size is capped at 10MB.
  /// 
  /// For other HTTP methods, or when the Content-Type is not
  /// application/x-www-form-urlencoded, the request Body is not read, and
  /// r.PostForm is initialized to a non-nil, empty value.
  /// 
  /// [Request.ParseMultipartForm] calls ParseForm automatically.
  /// ParseForm is idempotent.
  fn ParseForm(self: Ref<Request>) -> Result<(), error>

  /// ParseMultipartForm parses a request body as multipart/form-data.
  /// The whole request body is parsed and up to a total of maxMemory bytes of
  /// its file parts are stored in memory, with the remainder stored on
  /// disk in temporary files.
  /// ParseMultipartForm calls [Request.ParseForm] if necessary.
  /// If ParseForm returns an error, ParseMultipartForm returns it but also
  /// continues parsing the request body.
  /// After one call to ParseMultipartForm, subsequent calls have no effect.
  fn ParseMultipartForm(self: Ref<Request>, maxMemory: int64) -> Result<(), error>

  /// PathValue returns the value for the named path wildcard in the [ServeMux] pattern
  /// that matched the request.
  /// It returns the empty string if the request was not matched against a pattern
  /// or there is no such wildcard in the pattern.
  fn PathValue(self: Ref<Request>, name: string) -> string

  /// PostFormValue returns the first value for the named component of the POST,
  /// PUT, or PATCH request body. URL query parameters are ignored.
  /// PostFormValue calls [Request.ParseMultipartForm] and [Request.ParseForm] if necessary and ignores
  /// any errors returned by these functions.
  /// If key is not present, PostFormValue returns the empty string.
  fn PostFormValue(self: Ref<Request>, key: string) -> string

  /// ProtoAtLeast reports whether the HTTP protocol used
  /// in the request is at least major.minor.
  fn ProtoAtLeast(self: Ref<Request>, major: int, minor: int) -> bool

  /// Referer returns the referring URL, if sent in the request.
  /// 
  /// Referer is misspelled as in the request itself, a mistake from the
  /// earliest days of HTTP.  This value can also be fetched from the
  /// [Header] map as Header["Referer"]; the benefit of making it available
  /// as a method is that the compiler can diagnose programs that use the
  /// alternate (correct English) spelling req.Referrer() but cannot
  /// diagnose programs that use Header["Referrer"].
  fn Referer(self: Ref<Request>) -> string

  /// SetBasicAuth sets the request's Authorization header to use HTTP
  /// Basic Authentication with the provided username and password.
  /// 
  /// With HTTP Basic Authentication the provided username and password
  /// are not encrypted. It should generally only be used in an HTTPS
  /// request.
  /// 
  /// The username may not contain a colon. Some protocols may impose
  /// additional requirements on pre-escaping the username and
  /// password. For instance, when used with OAuth2, both arguments must
  /// be URL encoded first with [url.QueryEscape].
  fn SetBasicAuth(self: Ref<Request>, username: string, password: string)

  /// SetPathValue sets name to value, so that subsequent calls to r.PathValue(name)
  /// return value.
  fn SetPathValue(self: Ref<Request>, name: string, value: string)

  /// UserAgent returns the client's User-Agent, if sent in the request.
  fn UserAgent(self: Ref<Request>) -> string

  /// WithContext returns a shallow copy of r with its context changed
  /// to ctx. The provided ctx must be non-nil.
  /// 
  /// For outgoing client request, the context controls the entire
  /// lifetime of a request and its response: obtaining a connection,
  /// sending the request, and reading the response headers and body.
  /// 
  /// To create a new request with a context, use [NewRequestWithContext].
  /// To make a deep copy of a request with a new context, use [Request.Clone].
  fn WithContext(self: Ref<Request>, ctx: context.Context) -> Ref<Request>

  /// Write writes an HTTP/1.1 request, which is the header and body, in wire format.
  /// This method consults the following fields of the request:
  /// 
  /// 	Host
  /// 	URL
  /// 	Method (defaults to "GET")
  /// 	Header
  /// 	ContentLength
  /// 	TransferEncoding
  /// 	Body
  /// 
  /// If Body is present, Content-Length is <= 0 and [Request.TransferEncoding]
  /// hasn't been set to "identity", Write adds "Transfer-Encoding:
  /// chunked" to the header. Body is closed after it is sent.
  fn Write(self: Ref<Request>, w: io.Writer) -> Result<(), error>

  /// WriteProxy is like [Request.Write] but writes the request in the form
  /// expected by an HTTP proxy. In particular, [Request.WriteProxy] writes the
  /// initial Request-URI line of the request with an absolute URI, per
  /// section 5.3 of RFC 7230, including the scheme and host.
  /// In either case, WriteProxy also writes a Host header, using
  /// either r.Host or r.URL.Host.
  fn WriteProxy(self: Ref<Request>, w: io.Writer) -> Result<(), error>
}

impl Response {
  /// Cookies parses and returns the cookies set in the Set-Cookie headers.
  fn Cookies(self: Ref<Response>) -> Slice<Ref<Cookie>>

  /// Location returns the URL of the response's "Location" header,
  /// if present. Relative redirects are resolved relative to
  /// [Response.Request]. [ErrNoLocation] is returned if no
  /// Location header is present.
  fn Location(self: Ref<Response>) -> Result<Ref<url.URL>, error>

  /// ProtoAtLeast reports whether the HTTP protocol used
  /// in the response is at least major.minor.
  fn ProtoAtLeast(self: Ref<Response>, major: int, minor: int) -> bool

  /// Write writes r to w in the HTTP/1.x server response format,
  /// including the status line, headers, body, and optional trailer.
  /// 
  /// This method consults the following fields of the response r:
  /// 
  /// 	StatusCode
  /// 	ProtoMajor
  /// 	ProtoMinor
  /// 	Request.Method
  /// 	TransferEncoding
  /// 	Trailer
  /// 	Body
  /// 	ContentLength
  /// 	Header, values for non-canonical keys will have unpredictable behavior
  /// 
  /// The Response Body is closed after it is sent.
  fn Write(self: Ref<Response>, w: io.Writer) -> Result<(), error>
}

impl ResponseController {
  /// EnableFullDuplex indicates that the request handler will interleave reads from [Request.Body]
  /// with writes to the [ResponseWriter].
  /// 
  /// For HTTP/1 requests, the Go HTTP server by default consumes any unread portion of
  /// the request body before beginning to write the response, preventing handlers from
  /// concurrently reading from the request and writing the response.
  /// Calling EnableFullDuplex disables this behavior and permits handlers to continue to read
  /// from the request while concurrently writing the response.
  /// 
  /// For HTTP/2 requests, the Go HTTP server always permits concurrent reads and responses.
  fn EnableFullDuplex(self: Ref<ResponseController>) -> Result<(), error>

  /// Flush flushes buffered data to the client.
  #[allow(unused_result)]
  fn Flush(self: Ref<ResponseController>) -> Result<(), error>

  /// Hijack lets the caller take over the connection.
  /// See the [Hijacker] interface for details.
  fn Hijack(self: Ref<ResponseController>) -> Result<(net.Conn, Ref<bufio.ReadWriter>), error>

  /// SetReadDeadline sets the deadline for reading the entire request, including the body.
  /// Reads from the request body after the deadline has been exceeded will return an error.
  /// A zero value means no deadline.
  /// 
  /// Setting the read deadline after it has been exceeded will not extend it.
  fn SetReadDeadline(self: Ref<ResponseController>, deadline: time.Time) -> Result<(), error>

  /// SetWriteDeadline sets the deadline for writing the response.
  /// Writes to the response body after the deadline has been exceeded will not block,
  /// but may succeed if the data has been buffered.
  /// A zero value means no deadline.
  /// 
  /// Setting the write deadline after it has been exceeded will not extend it.
  fn SetWriteDeadline(self: Ref<ResponseController>, deadline: time.Time) -> Result<(), error>
}

impl ServeMux {
  /// Handle registers the handler for the given pattern.
  /// If the given pattern conflicts with one that is already registered, Handle
  /// panics.
  fn Handle(self: Ref<ServeMux>, pattern: string, handler: Handler)

  /// HandleFunc registers the handler function for the given pattern.
  /// If the given pattern conflicts with one that is already registered, HandleFunc
  /// panics.
  fn HandleFunc(
    self: Ref<ServeMux>,
    pattern: string,
    handler: fn(ResponseWriter, Ref<Request>) -> (),
  )

  /// Handler returns the handler to use for the given request,
  /// consulting r.Method, r.Host, and r.URL.Path. It always returns
  /// a non-nil handler. If the path is not in its canonical form, the
  /// handler will be an internally-generated handler that redirects
  /// to the canonical path. If the host contains a port, it is ignored
  /// when matching handlers.
  /// 
  /// The path and host are used unchanged for CONNECT requests.
  /// 
  /// Handler also returns the registered pattern that matches the
  /// request or, in the case of internally-generated redirects,
  /// the path that will match after following the redirect.
  /// 
  /// If there is no registered handler that applies to the request,
  /// Handler returns a “page not found” or “method not supported”
  /// handler and an empty pattern.
  /// 
  /// Handler does not modify its argument. In particular, it does not
  /// populate named path wildcards, so r.PathValue will always return
  /// the empty string.
  fn Handler(self: Ref<ServeMux>, r: Ref<Request>) -> (Handler, string)

  /// ServeHTTP dispatches the request to the handler whose
  /// pattern most closely matches the request URL.
  fn ServeHTTP(self: Ref<ServeMux>, w: ResponseWriter, r: Ref<Request>)
}

impl Server {
  /// Close immediately closes all active net.Listeners and any
  /// connections in state [StateNew], [StateActive], or [StateIdle]. For a
  /// graceful shutdown, use [Server.Shutdown].
  /// 
  /// Close does not attempt to close (and does not even know about)
  /// any hijacked connections, such as WebSockets.
  /// 
  /// Close returns any error returned from closing the [Server]'s
  /// underlying Listener(s).
  #[allow(unused_result)]
  fn Close(self: Ref<Server>) -> Result<(), error>

  /// ListenAndServe listens on the TCP network address s.Addr and then
  /// calls [Serve] to handle requests on incoming connections.
  /// Accepted connections are configured to enable TCP keep-alives.
  /// 
  /// If s.Addr is blank, ":http" is used.
  /// 
  /// ListenAndServe always returns a non-nil error. After [Server.Shutdown] or [Server.Close],
  /// the returned error is [ErrServerClosed].
  fn ListenAndServe(self: Ref<Server>) -> Result<(), error>

  /// ListenAndServeTLS listens on the TCP network address s.Addr and
  /// then calls [ServeTLS] to handle requests on incoming TLS connections.
  /// Accepted connections are configured to enable TCP keep-alives.
  /// 
  /// Filenames containing a certificate and matching private key for the
  /// server must be provided if neither the [Server]'s TLSConfig.Certificates
  /// nor TLSConfig.GetCertificate are populated. If the certificate is
  /// signed by a certificate authority, the certFile should be the
  /// concatenation of the server's certificate, any intermediates, and
  /// the CA's certificate.
  /// 
  /// If s.Addr is blank, ":https" is used.
  /// 
  /// ListenAndServeTLS always returns a non-nil error. After [Server.Shutdown] or
  /// [Server.Close], the returned error is [ErrServerClosed].
  fn ListenAndServeTLS(self: Ref<Server>, certFile: string, keyFile: string) -> Result<(), error>

  /// RegisterOnShutdown registers a function to call on [Server.Shutdown].
  /// This can be used to gracefully shutdown connections that have
  /// undergone ALPN protocol upgrade or that have been hijacked.
  /// This function should start protocol-specific graceful shutdown,
  /// but should not wait for shutdown to complete.
  fn RegisterOnShutdown(self: Ref<Server>, f: fn() -> ())

  /// Serve accepts incoming connections on the Listener l, creating a
  /// new service goroutine for each. The service goroutines read requests and
  /// then call s.Handler to reply to them.
  /// 
  /// HTTP/2 support is only enabled if the Listener returns [*tls.Conn]
  /// connections and they were configured with "h2" in the TLS
  /// Config.NextProtos.
  /// 
  /// Serve always returns a non-nil error and closes l.
  /// After [Server.Shutdown] or [Server.Close], the returned error is [ErrServerClosed].
  fn Serve(self: Ref<Server>, l: net.Listener) -> Result<(), error>

  /// ServeTLS accepts incoming connections on the Listener l, creating a
  /// new service goroutine for each. The service goroutines perform TLS
  /// setup and then read requests, calling s.Handler to reply to them.
  /// 
  /// Files containing a certificate and matching private key for the
  /// server must be provided if neither the [Server]'s
  /// TLSConfig.Certificates, TLSConfig.GetCertificate nor
  /// config.GetConfigForClient are populated.
  /// If the certificate is signed by a certificate authority, the
  /// certFile should be the concatenation of the server's certificate,
  /// any intermediates, and the CA's certificate.
  /// 
  /// ServeTLS always returns a non-nil error. After [Server.Shutdown] or [Server.Close], the
  /// returned error is [ErrServerClosed].
  fn ServeTLS(
    self: Ref<Server>,
    l: net.Listener,
    certFile: string,
    keyFile: string,
  ) -> Result<(), error>

  /// SetKeepAlivesEnabled controls whether HTTP keep-alives are enabled.
  /// By default, keep-alives are always enabled. Only very
  /// resource-constrained environments or servers in the process of
  /// shutting down should disable them.
  fn SetKeepAlivesEnabled(self: Ref<Server>, v: bool)

  /// Shutdown gracefully shuts down the server without interrupting any
  /// active connections. Shutdown works by first closing all open
  /// listeners, then closing all idle connections, and then waiting
  /// indefinitely for connections to return to idle and then shut down.
  /// If the provided context expires before the shutdown is complete,
  /// Shutdown returns the context's error, otherwise it returns any
  /// error returned from closing the [Server]'s underlying Listener(s).
  /// 
  /// When Shutdown is called, [Serve], [ServeTLS], [ListenAndServe], and
  /// [ListenAndServeTLS] immediately return [ErrServerClosed]. Make sure the
  /// program doesn't exit and waits instead for Shutdown to return.
  /// 
  /// Shutdown does not attempt to close nor wait for hijacked
  /// connections such as WebSockets. The caller of Shutdown should
  /// separately notify such long-lived connections of shutdown and wait
  /// for them to close, if desired. See [Server.RegisterOnShutdown] for a way to
  /// register shutdown notification functions.
  /// 
  /// Once Shutdown has been called on a server, it may not be reused;
  /// future calls to methods such as Serve will return ErrServerClosed.
  fn Shutdown(self: Ref<Server>, ctx: context.Context) -> Result<(), error>
}

impl Transport {
  /// CancelRequest cancels an in-flight request by closing its connection.
  /// CancelRequest should only be called after [Transport.RoundTrip] has returned.
  /// 
  /// Deprecated: Use [Request.WithContext] to create a request with a
  /// cancelable context instead. CancelRequest cannot cancel HTTP/2
  /// requests. This may become a no-op in a future release of Go.
  fn CancelRequest(self: Ref<Transport>, req: Ref<Request>)

  /// Clone returns a deep copy of t's exported fields.
  fn Clone(self: Ref<Transport>) -> Ref<Transport>

  /// CloseIdleConnections closes any connections which were previously
  /// connected from previous requests but are now sitting idle in
  /// a "keep-alive" state. It does not interrupt any connections currently
  /// in use.
  fn CloseIdleConnections(self: Ref<Transport>)

  /// RegisterProtocol registers a new protocol with scheme.
  /// The [Transport] will pass requests using the given scheme to rt.
  /// It is rt's responsibility to simulate HTTP request semantics.
  /// 
  /// RegisterProtocol can be used by other packages to provide
  /// implementations of protocol schemes like "ftp" or "file".
  /// 
  /// If rt.RoundTrip returns [ErrSkipAltProtocol], the Transport will
  /// handle the [Transport.RoundTrip] itself for that one request, as if the
  /// protocol were not registered.
  fn RegisterProtocol(self: Ref<Transport>, scheme: string, rt: RoundTripper)

  /// RoundTrip implements the [RoundTripper] interface.
  /// 
  /// For higher-level HTTP client support (such as handling of cookies
  /// and redirects), see [Get], [Post], and the [Client] type.
  /// 
  /// Like the RoundTripper interface, the error types returned
  /// by RoundTrip are unspecified.
  fn RoundTrip(self: Ref<Transport>, req: Ref<Request>) -> Result<Ref<Response>, error>
}