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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{Message, SessionFeature, WebsocketConnection};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, pin::Pin};
glib::wrapper! {
/// Soup session state object.
///
/// #SoupSession is the object that controls client-side HTTP. A
/// #SoupSession encapsulates all of the state that libsoup is keeping
/// on behalf of your program; cached HTTP connections, authentication
/// information, etc. It also keeps track of various global options
/// and features that you are using.
///
/// Most applications will only need a single #SoupSession; the primary
/// reason you might need multiple sessions is if you need to have
/// multiple independent authentication contexts. (Eg, you are
/// connecting to a server and authenticating as two different users at
/// different times; the easiest way to ensure that each [`Message`][crate::Message]
/// is sent with the authentication information you intended is to use
/// one session for the first user, and a second session for the other
/// user.)
///
/// Additional #SoupSession functionality is provided by
/// [`SessionFeature`][crate::SessionFeature] objects, which can be added to a session with
/// [`SessionExt::add_feature()`][crate::prelude::SessionExt::add_feature()] or [`SessionExt::add_feature_by_type()`][crate::prelude::SessionExt::add_feature_by_type()]
/// For example, [`Logger`][crate::Logger] provides support for
/// logging HTTP traffic, [`ContentDecoder`][crate::ContentDecoder] provides support for
/// compressed response handling, and [`ContentSniffer`][crate::ContentSniffer] provides
/// support for HTML5-style response body content sniffing.
/// Additionally, subtypes of [`Auth`][crate::Auth] can be added
/// as features, to add support for additional authentication types.
///
/// All `SoupSession`s are created with a [`AuthManager`][crate::AuthManager], and support
/// for `SOUP_TYPE_AUTH_BASIC` and `SOUP_TYPE_AUTH_DIGEST`. Additionally,
/// sessions using the plain #SoupSession class (rather than one of its deprecated
/// subtypes) have a [`ContentDecoder`][crate::ContentDecoder] by default.
///
/// Note that all async methods will invoke their callbacks on the thread-default
/// context at the time of the function call.
///
/// ## Properties
///
///
/// #### `accept-language`
/// If non-[`None`], the value to use for the "Accept-Language" header
/// on [`Message`][crate::Message]s sent from this session.
///
/// Setting this will disable [`accept-language-auto`][struct@crate::Session#accept-language-auto].
///
/// Readable | Writeable
///
///
/// #### `accept-language-auto`
/// If [`true`], #SoupSession will automatically set the string
/// for the "Accept-Language" header on every [`Message`][crate::Message]
/// sent, based on the return value of `get_language_names()`.
///
/// Setting this will override any previous value of
/// [`accept-language`][struct@crate::Session#accept-language].
///
/// Readable | Writeable
///
///
/// #### `idle-timeout`
/// Connection lifetime (in seconds) when idle. Any connection
/// left idle longer than this will be closed.
///
/// Although you can change this property at any time, it will
/// only affect newly-created connections, not currently-open
/// ones. You can call [`SessionExt::abort()`][crate::prelude::SessionExt::abort()] after setting this
/// if you want to ensure that all future connections will have
/// this timeout value.
///
/// Readable | Writeable
///
///
/// #### `local-address`
/// Sets the [`gio::InetSocketAddress`][crate::gio::InetSocketAddress] to use for the client side of
/// the connection.
///
/// Use this property if you want for instance to bind the
/// local socket to a specific IP address.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `max-conns`
/// The maximum number of connections that the session can open at once.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `max-conns-per-host`
/// The maximum number of connections that the session can open at once
/// to a given host.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `proxy-resolver`
/// A [`gio::ProxyResolver`][crate::gio::ProxyResolver] to use with this session.
///
/// If no proxy resolver is set, then the default proxy resolver
/// will be used. See [`gio::ProxyResolver::default()`][crate::gio::ProxyResolver::default()].
/// You can set it to [`None`] if you don't want to use proxies, or
/// set it to your own [`gio::ProxyResolver`][crate::gio::ProxyResolver] if you want to control
/// what proxies get used.
///
/// Readable | Writeable
///
///
/// #### `remote-connectable`
/// Sets a socket to make outgoing connections on. This will override the default
/// behaviour of opening TCP/IP sockets to the hosts specified in the URIs.
///
/// This function is not required for common HTTP usage, but only when connecting
/// to a HTTP service that is not using standard TCP/IP sockets. An example of
/// this is a local service that uses HTTP over UNIX-domain sockets, in that case
/// a `Gio::UnixSocketAddress` can be passed to this function.
///
/// Readable | Writeable | Construct Only
///
///
/// #### `timeout`
/// The timeout (in seconds) for socket I/O operations
/// (including connecting to a server, and waiting for a reply
/// to an HTTP request).
///
/// Although you can change this property at any time, it will
/// only affect newly-created connections, not currently-open
/// ones. You can call [`SessionExt::abort()`][crate::prelude::SessionExt::abort()] after setting this
/// if you want to ensure that all future connections will have
/// this timeout value.
///
/// Not to be confused with [`idle-timeout`][struct@crate::Session#idle-timeout] (which is
/// the length of time that idle persistent connections will be
/// kept open).
///
/// Readable | Writeable
///
///
/// #### `tls-database`
/// Sets the [`gio::TlsDatabase`][crate::gio::TlsDatabase] to use for validating SSL/TLS
/// certificates.
///
/// If no certificate database is set, then the default database will be
/// used. See `Gio::TlsBackend::get_default_database()`.
///
/// Readable | Writeable
///
///
/// #### `tls-interaction`
/// A [`gio::TlsInteraction`][crate::gio::TlsInteraction] object that will be passed on to any
/// `Gio::TlsConnection`s created by the session.
///
/// This can be used to provide client-side certificates, for example.
///
/// Readable | Writeable
///
///
/// #### `user-agent`
/// User-Agent string.
///
/// If non-[`None`], the value to use for the "User-Agent" header
/// on [`Message`][crate::Message]s sent from this session.
///
/// RFC 2616 says: "The User-Agent request-header field
/// contains information about the user agent originating the
/// request. This is for statistical purposes, the tracing of
/// protocol violations, and automated recognition of user
/// agents for the sake of tailoring responses to avoid
/// particular user agent limitations. User agents SHOULD
/// include this field with requests."
///
/// The User-Agent header contains a list of one or more
/// product tokens, separated by whitespace, with the most
/// significant product token coming first. The tokens must be
/// brief, ASCII, and mostly alphanumeric (although "-", "_",
/// and "." are also allowed), and may optionally include a "/"
/// followed by a version string. You may also put comments,
/// enclosed in parentheses, between or after the tokens.
///
/// If you set a [`user-agent`][struct@crate::Session#user-agent] property that has trailing
/// whitespace, #SoupSession will append its own product token
/// (eg, `libsoup/2.3.2`) to the end of the
/// header for you.
///
/// Readable | Writeable
///
/// ## Signals
///
///
/// #### `request-queued`
/// Emitted when a request is queued on @session.
///
/// When sending a request, first [`request-queued`][struct@crate::Session#request-queued]
/// is emitted, indicating that the session has become aware of
/// the request.
///
/// After a connection is available to send the request various
/// [`Message`][crate::Message] signals are emitted as the message is
/// processed. If the message is requeued, it will emit
/// [`restarted`][struct@crate::Message#restarted], which will then be followed by other
/// [`Message`][crate::Message] signals when the message is re-sent.
///
/// Eventually, the message will emit [`finished`][struct@crate::Message#finished].
/// Normally, this signals the completion of message
/// processing. However, it is possible that the application
/// will requeue the message from the "finished" handler.
/// In that case the process will loop back.
///
/// Eventually, a message will reach "finished" and not be
/// requeued. At that point, the session will emit
/// [`request-unqueued`][struct@crate::Session#request-unqueued] to indicate that it is done
/// with the message.
///
/// To sum up: [`request-queued`][struct@crate::Session#request-queued] and
/// [`request-unqueued`][struct@crate::Session#request-unqueued] are guaranteed to be emitted
/// exactly once, but [`finished`][struct@crate::Message#finished] (and all of the other
/// [`Message`][crate::Message] signals) may be invoked multiple times for a given
/// message.
///
///
///
///
/// #### `request-unqueued`
/// Emitted when a request is removed from @session's queue,
/// indicating that @session is done with it.
///
/// See [`request-queued`][struct@crate::Session#request-queued] for a detailed description of
/// the message lifecycle within a session.
///
///
///
/// # Implements
///
/// [`SessionExt`][trait@crate::prelude::SessionExt], [`trait@glib::ObjectExt`], [`SessionExtManual`][trait@crate::prelude::SessionExtManual]
#[doc(alias = "SoupSession")]
pub struct Session(Object<ffi::SoupSession, ffi::SoupSessionClass>);
match fn {
type_ => || ffi::soup_session_get_type(),
}
}
impl Session {
pub const NONE: Option<&'static Session> = None;
/// Creates a #SoupSession with the default options.
///
/// # Returns
///
/// the new session.
#[doc(alias = "soup_session_new")]
pub fn new() -> Session {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::soup_session_new()) }
}
//#[doc(alias = "soup_session_new_with_options")]
//#[doc(alias = "new_with_options")]
//pub fn with_options(optname1: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Session {
// unsafe { TODO: call ffi:soup_session_new_with_options() }
//}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`Session`] objects.
///
/// This method returns an instance of [`SessionBuilder`](crate::builders::SessionBuilder) which can be used to create [`Session`] objects.
pub fn builder() -> SessionBuilder {
SessionBuilder::new()
}
}
impl Default for Session {
fn default() -> Self {
Self::new()
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Session`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct SessionBuilder {
builder: glib::object::ObjectBuilder<'static, Session>,
}
impl SessionBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
/// If non-[`None`], the value to use for the "Accept-Language" header
/// on [`Message`][crate::Message]s sent from this session.
///
/// Setting this will disable [`accept-language-auto`][struct@crate::Session#accept-language-auto].
pub fn accept_language(self, accept_language: impl Into<glib::GString>) -> Self {
Self {
builder: self
.builder
.property("accept-language", accept_language.into()),
}
}
/// If [`true`], #SoupSession will automatically set the string
/// for the "Accept-Language" header on every [`Message`][crate::Message]
/// sent, based on the return value of `get_language_names()`.
///
/// Setting this will override any previous value of
/// [`accept-language`][struct@crate::Session#accept-language].
pub fn accept_language_auto(self, accept_language_auto: bool) -> Self {
Self {
builder: self
.builder
.property("accept-language-auto", accept_language_auto),
}
}
/// Connection lifetime (in seconds) when idle. Any connection
/// left idle longer than this will be closed.
///
/// Although you can change this property at any time, it will
/// only affect newly-created connections, not currently-open
/// ones. You can call [`SessionExt::abort()`][crate::prelude::SessionExt::abort()] after setting this
/// if you want to ensure that all future connections will have
/// this timeout value.
pub fn idle_timeout(self, idle_timeout: u32) -> Self {
Self {
builder: self.builder.property("idle-timeout", idle_timeout),
}
}
/// Sets the [`gio::InetSocketAddress`][crate::gio::InetSocketAddress] to use for the client side of
/// the connection.
///
/// Use this property if you want for instance to bind the
/// local socket to a specific IP address.
pub fn local_address(self, local_address: &impl IsA<gio::InetSocketAddress>) -> Self {
Self {
builder: self
.builder
.property("local-address", local_address.clone().upcast()),
}
}
/// The maximum number of connections that the session can open at once.
pub fn max_conns(self, max_conns: i32) -> Self {
Self {
builder: self.builder.property("max-conns", max_conns),
}
}
/// The maximum number of connections that the session can open at once
/// to a given host.
pub fn max_conns_per_host(self, max_conns_per_host: i32) -> Self {
Self {
builder: self
.builder
.property("max-conns-per-host", max_conns_per_host),
}
}
/// A [`gio::ProxyResolver`][crate::gio::ProxyResolver] to use with this session.
///
/// If no proxy resolver is set, then the default proxy resolver
/// will be used. See [`gio::ProxyResolver::default()`][crate::gio::ProxyResolver::default()].
/// You can set it to [`None`] if you don't want to use proxies, or
/// set it to your own [`gio::ProxyResolver`][crate::gio::ProxyResolver] if you want to control
/// what proxies get used.
pub fn proxy_resolver(self, proxy_resolver: &impl IsA<gio::ProxyResolver>) -> Self {
Self {
builder: self
.builder
.property("proxy-resolver", proxy_resolver.clone().upcast()),
}
}
/// Sets a socket to make outgoing connections on. This will override the default
/// behaviour of opening TCP/IP sockets to the hosts specified in the URIs.
///
/// This function is not required for common HTTP usage, but only when connecting
/// to a HTTP service that is not using standard TCP/IP sockets. An example of
/// this is a local service that uses HTTP over UNIX-domain sockets, in that case
/// a `Gio::UnixSocketAddress` can be passed to this function.
pub fn remote_connectable(self, remote_connectable: &impl IsA<gio::SocketConnectable>) -> Self {
Self {
builder: self
.builder
.property("remote-connectable", remote_connectable.clone().upcast()),
}
}
/// The timeout (in seconds) for socket I/O operations
/// (including connecting to a server, and waiting for a reply
/// to an HTTP request).
///
/// Although you can change this property at any time, it will
/// only affect newly-created connections, not currently-open
/// ones. You can call [`SessionExt::abort()`][crate::prelude::SessionExt::abort()] after setting this
/// if you want to ensure that all future connections will have
/// this timeout value.
///
/// Not to be confused with [`idle-timeout`][struct@crate::Session#idle-timeout] (which is
/// the length of time that idle persistent connections will be
/// kept open).
pub fn timeout(self, timeout: u32) -> Self {
Self {
builder: self.builder.property("timeout", timeout),
}
}
/// Sets the [`gio::TlsDatabase`][crate::gio::TlsDatabase] to use for validating SSL/TLS
/// certificates.
///
/// If no certificate database is set, then the default database will be
/// used. See `Gio::TlsBackend::get_default_database()`.
pub fn tls_database(self, tls_database: &impl IsA<gio::TlsDatabase>) -> Self {
Self {
builder: self
.builder
.property("tls-database", tls_database.clone().upcast()),
}
}
/// A [`gio::TlsInteraction`][crate::gio::TlsInteraction] object that will be passed on to any
/// `Gio::TlsConnection`s created by the session.
///
/// This can be used to provide client-side certificates, for example.
pub fn tls_interaction(self, tls_interaction: &impl IsA<gio::TlsInteraction>) -> Self {
Self {
builder: self
.builder
.property("tls-interaction", tls_interaction.clone().upcast()),
}
}
/// User-Agent string.
///
/// If non-[`None`], the value to use for the "User-Agent" header
/// on [`Message`][crate::Message]s sent from this session.
///
/// RFC 2616 says: "The User-Agent request-header field
/// contains information about the user agent originating the
/// request. This is for statistical purposes, the tracing of
/// protocol violations, and automated recognition of user
/// agents for the sake of tailoring responses to avoid
/// particular user agent limitations. User agents SHOULD
/// include this field with requests."
///
/// The User-Agent header contains a list of one or more
/// product tokens, separated by whitespace, with the most
/// significant product token coming first. The tokens must be
/// brief, ASCII, and mostly alphanumeric (although "-", "_",
/// and "." are also allowed), and may optionally include a "/"
/// followed by a version string. You may also put comments,
/// enclosed in parentheses, between or after the tokens.
///
/// If you set a [`user-agent`][struct@crate::Session#user-agent] property that has trailing
/// whitespace, #SoupSession will append its own product token
/// (eg, `libsoup/2.3.2`) to the end of the
/// header for you.
pub fn user_agent(self, user_agent: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("user-agent", user_agent.into()),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`Session`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Session {
self.builder.build()
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Session>> Sealed for T {}
}
/// Trait containing all [`struct@Session`] methods.
///
/// # Implementors
///
/// [`Session`][struct@crate::Session]
pub trait SessionExt: IsA<Session> + sealed::Sealed + 'static {
/// Cancels all pending requests in @self and closes all idle
/// persistent connections.
#[doc(alias = "soup_session_abort")]
fn abort(&self) {
unsafe {
ffi::soup_session_abort(self.as_ref().to_glib_none().0);
}
}
/// Adds @feature's functionality to @self. You cannot add multiple
/// features of the same `alias::GLib.Type` to a session.
///
/// See the main #SoupSession documentation for information on what
/// features are present in sessions by default.
/// ## `feature`
/// an object that implements #SoupSessionFeature
#[doc(alias = "soup_session_add_feature")]
fn add_feature(&self, feature: &impl IsA<SessionFeature>) {
unsafe {
ffi::soup_session_add_feature(
self.as_ref().to_glib_none().0,
feature.as_ref().to_glib_none().0,
);
}
}
/// If @feature_type is the type of a class that implements
/// [`SessionFeature`][crate::SessionFeature], this creates a new feature of that type and
/// adds it to @self as with [`add_feature()`][Self::add_feature()]. You can use
/// this when you don't need to customize the new feature in any way.
/// Adding multiple features of the same @feature_type is not allowed.
///
/// If @feature_type is not a [`SessionFeature`][crate::SessionFeature] type, this gives each
/// existing feature on @self the chance to accept @feature_type as
/// a "subfeature". This can be used to add new [`Auth`][crate::Auth] types, for instance.
///
/// See the main #SoupSession documentation for information on what
/// features are present in sessions by default.
/// ## `feature_type`
/// a #GType
#[doc(alias = "soup_session_add_feature_by_type")]
fn add_feature_by_type(&self, feature_type: glib::types::Type) {
unsafe {
ffi::soup_session_add_feature_by_type(
self.as_ref().to_glib_none().0,
feature_type.into_glib(),
);
}
}
/// Get the value used by @self for the "Accept-Language" header on new
/// requests.
///
/// # Returns
///
/// the accept language string
#[doc(alias = "soup_session_get_accept_language")]
#[doc(alias = "get_accept_language")]
fn accept_language(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::soup_session_get_accept_language(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets whether @self automatically sets the "Accept-Language" header on new
/// requests.
///
/// # Returns
///
/// [`true`] if @self sets "Accept-Language" header automatically, or
/// [`false`] otherwise.
#[doc(alias = "soup_session_get_accept_language_auto")]
#[doc(alias = "get_accept_language_auto")]
fn accepts_language_auto(&self) -> bool {
unsafe {
from_glib(ffi::soup_session_get_accept_language_auto(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the [`Message`][crate::Message] of the @result asynchronous operation This is useful
/// to get the [`Message`][crate::Message] of an asynchronous operation started by @self
/// from its `callback::Gio::AsyncReadyCallback.
/// ## `result`
/// the #GAsyncResult passed to your callback
///
/// # Returns
///
/// a #SoupMessage or
/// [`None`] if @result is not a valid @self async operation result.
#[doc(alias = "soup_session_get_async_result_message")]
#[doc(alias = "get_async_result_message")]
fn async_result_message(&self, result: &impl IsA<gio::AsyncResult>) -> Option<Message> {
unsafe {
from_glib_none(ffi::soup_session_get_async_result_message(
self.as_ref().to_glib_none().0,
result.as_ref().to_glib_none().0,
))
}
}
/// Gets the feature in @self of type @feature_type.
/// ## `feature_type`
/// the #GType of the feature to get
///
/// # Returns
///
/// a #SoupSessionFeature, or [`None`]. The
/// feature is owned by @self.
#[doc(alias = "soup_session_get_feature")]
#[doc(alias = "get_feature")]
fn feature(&self, feature_type: glib::types::Type) -> Option<SessionFeature> {
unsafe {
from_glib_none(ffi::soup_session_get_feature(
self.as_ref().to_glib_none().0,
feature_type.into_glib(),
))
}
}
/// Gets the feature in @self of type @feature_type, provided
/// that it is not disabled for @msg.
/// ## `feature_type`
/// the #GType of the feature to get
/// ## `msg`
/// a #SoupMessage
///
/// # Returns
///
/// a #SoupSessionFeature. The feature is
/// owned by @self.
#[doc(alias = "soup_session_get_feature_for_message")]
#[doc(alias = "get_feature_for_message")]
fn feature_for_message(
&self,
feature_type: glib::types::Type,
msg: &Message,
) -> Option<SessionFeature> {
unsafe {
from_glib_none(ffi::soup_session_get_feature_for_message(
self.as_ref().to_glib_none().0,
feature_type.into_glib(),
msg.to_glib_none().0,
))
}
}
/// Get the timeout in seconds for idle connection lifetime currently used by
/// @self.
///
/// # Returns
///
/// the timeout in seconds
#[doc(alias = "soup_session_get_idle_timeout")]
#[doc(alias = "get_idle_timeout")]
fn idle_timeout(&self) -> u32 {
unsafe { ffi::soup_session_get_idle_timeout(self.as_ref().to_glib_none().0) }
}
/// Get the [`gio::InetSocketAddress`][crate::gio::InetSocketAddress] to use for the client side of
/// connections in @self.
///
/// # Returns
///
/// a #GInetSocketAddress
#[doc(alias = "soup_session_get_local_address")]
#[doc(alias = "get_local_address")]
fn local_address(&self) -> Option<gio::InetSocketAddress> {
unsafe {
from_glib_none(ffi::soup_session_get_local_address(
self.as_ref().to_glib_none().0,
))
}
}
/// Get the maximum number of connections that @self can open at once.
///
/// # Returns
///
/// the maximum number of connections
#[doc(alias = "soup_session_get_max_conns")]
#[doc(alias = "get_max_conns")]
fn max_conns(&self) -> u32 {
unsafe { ffi::soup_session_get_max_conns(self.as_ref().to_glib_none().0) }
}
/// Get the maximum number of connections that @self can open at once to a
/// given host.
///
/// # Returns
///
/// the maximum number of connections per host
#[doc(alias = "soup_session_get_max_conns_per_host")]
#[doc(alias = "get_max_conns_per_host")]
fn max_conns_per_host(&self) -> u32 {
unsafe { ffi::soup_session_get_max_conns_per_host(self.as_ref().to_glib_none().0) }
}
/// Get the [`gio::ProxyResolver`][crate::gio::ProxyResolver] currently used by @self.
///
/// # Returns
///
/// a #GProxyResolver or [`None`] if proxies
/// are disabled in @self
#[doc(alias = "soup_session_get_proxy_resolver")]
#[doc(alias = "get_proxy_resolver")]
fn proxy_resolver(&self) -> Option<gio::ProxyResolver> {
unsafe {
from_glib_none(ffi::soup_session_get_proxy_resolver(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the remote connectable if one set.
///
/// # Returns
///
/// the #GSocketConnectable
#[doc(alias = "soup_session_get_remote_connectable")]
#[doc(alias = "get_remote_connectable")]
fn remote_connectable(&self) -> Option<gio::SocketConnectable> {
unsafe {
from_glib_none(ffi::soup_session_get_remote_connectable(
self.as_ref().to_glib_none().0,
))
}
}
/// Get the timeout in seconds for socket I/O operations currently used by
/// @self.
///
/// # Returns
///
/// the timeout in seconds
#[doc(alias = "soup_session_get_timeout")]
#[doc(alias = "get_timeout")]
fn timeout(&self) -> u32 {
unsafe { ffi::soup_session_get_timeout(self.as_ref().to_glib_none().0) }
}
/// Get the [`gio::TlsDatabase`][crate::gio::TlsDatabase] currently used by @self.
///
/// # Returns
///
/// a #GTlsDatabase
#[doc(alias = "soup_session_get_tls_database")]
#[doc(alias = "get_tls_database")]
fn tls_database(&self) -> Option<gio::TlsDatabase> {
unsafe {
from_glib_none(ffi::soup_session_get_tls_database(
self.as_ref().to_glib_none().0,
))
}
}
/// Get the [`gio::TlsInteraction`][crate::gio::TlsInteraction] currently used by @self.
///
/// # Returns
///
/// a #GTlsInteraction
#[doc(alias = "soup_session_get_tls_interaction")]
#[doc(alias = "get_tls_interaction")]
fn tls_interaction(&self) -> Option<gio::TlsInteraction> {
unsafe {
from_glib_none(ffi::soup_session_get_tls_interaction(
self.as_ref().to_glib_none().0,
))
}
}
/// Get the value used by @self for the "User-Agent" header on new requests.
///
/// # Returns
///
/// the user agent string
#[doc(alias = "soup_session_get_user_agent")]
#[doc(alias = "get_user_agent")]
fn user_agent(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::soup_session_get_user_agent(
self.as_ref().to_glib_none().0,
))
}
}
/// Tests if @self has at a feature of type @feature_type (which can
/// be the type of either a [`SessionFeature`][crate::SessionFeature], or else a subtype of
/// some class managed by another feature, such as [`Auth`][crate::Auth]).
/// ## `feature_type`
/// the #GType of the class of features to check for
///
/// # Returns
///
/// [`true`] or [`false`]
#[doc(alias = "soup_session_has_feature")]
fn has_feature(&self, feature_type: glib::types::Type) -> bool {
unsafe {
from_glib(ffi::soup_session_has_feature(
self.as_ref().to_glib_none().0,
feature_type.into_glib(),
))
}
}
/// Start a preconnection to @msg.
///
/// Once the connection is done, it will remain in idle state so that it can be
/// reused by future requests. If there's already an idle connection for the
/// given @msg host, the operation finishes successfully without creating a new
/// connection. If a new request for the given @msg host is made while the
/// preconnect is still ongoing, the request will take the ownership of the
/// connection and the preconnect operation will finish successfully (if there's
/// a connection error it will be handled by the request).
///
/// The operation finishes when the connection is done or an error occurred.
/// ## `msg`
/// a #SoupMessage
/// ## `io_priority`
/// the I/O priority of the request
/// ## `cancellable`
/// a #GCancellable
/// ## `callback`
/// the callback to invoke when the operation finishes
#[doc(alias = "soup_session_preconnect_async")]
fn preconnect_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
&self,
msg: &Message,
io_priority: glib::Priority,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn preconnect_async_trampoline<
P: FnOnce(Result<(), glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let _ = ffi::soup_session_preconnect_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = preconnect_async_trampoline::<P>;
unsafe {
ffi::soup_session_preconnect_async(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
io_priority.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
fn preconnect_future(
&self,
msg: &Message,
io_priority: glib::Priority,
) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
let msg = msg.clone();
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.preconnect_async(&msg, io_priority, Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
/// Removes @feature's functionality from @self.
/// ## `feature`
/// a feature that has previously been added to @self
#[doc(alias = "soup_session_remove_feature")]
fn remove_feature(&self, feature: &impl IsA<SessionFeature>) {
unsafe {
ffi::soup_session_remove_feature(
self.as_ref().to_glib_none().0,
feature.as_ref().to_glib_none().0,
);
}
}
/// Removes all features of type @feature_type (or any subclass of
/// @feature_type) from @self.
/// ## `feature_type`
/// a #GType
#[doc(alias = "soup_session_remove_feature_by_type")]
fn remove_feature_by_type(&self, feature_type: glib::types::Type) {
unsafe {
ffi::soup_session_remove_feature_by_type(
self.as_ref().to_glib_none().0,
feature_type.into_glib(),
);
}
}
/// Synchronously sends @msg and waits for the beginning of a response.
///
/// On success, a [`gio::InputStream`][crate::gio::InputStream] will be returned which you can use to
/// read the response body. ("Success" here means only that an HTTP
/// response was received and understood; it does not necessarily mean
/// that a 2xx class status code was received.)
///
/// If non-[`None`], @cancellable can be used to cancel the request;
/// [`send()`][Self::send()] will return a `G_IO_ERROR_CANCELLED` error. Note that
/// with requests that have side effects (eg, `POST`, `PUT`, `DELETE`) it is
/// possible that you might cancel the request after the server acts on it, but
/// before it returns a response, leaving the remote resource in an unknown
/// state.
///
/// If @msg is requeued due to a redirect or authentication, the
/// initial (`3xx/401/407`) response body will be suppressed, and
/// [`send()`][Self::send()] will only return once a final response has been
/// received.
/// ## `msg`
/// a #SoupMessage
/// ## `cancellable`
/// a #GCancellable
///
/// # Returns
///
/// a #GInputStream for reading the
/// response body, or [`None`] on error.
#[doc(alias = "soup_session_send")]
fn send(
&self,
msg: &Message,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<gio::InputStream, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::soup_session_send(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Synchronously sends @msg and reads the response body.
///
/// On success, a [`glib::Bytes`][crate::glib::Bytes] will be returned with the response body.
/// This function should only be used when the resource to be retrieved
/// is not too long and can be stored in memory.
///
/// See [`send()`][Self::send()] for more details on the general semantics.
/// ## `msg`
/// a #SoupMessage
/// ## `cancellable`
/// a #GCancellable
///
/// # Returns
///
/// a #GBytes, or [`None`] on error.
#[doc(alias = "soup_session_send_and_read")]
fn send_and_read(
&self,
msg: &Message,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<glib::Bytes, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::soup_session_send_and_read(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
/// Asynchronously sends @msg and reads the response body.
///
/// When @callback is called, then either @msg has been sent, and its response
/// body read, or else an error has occurred. This function should only be used
/// when the resource to be retrieved is not too long and can be stored in
/// memory. Call `Session::send_and_read_finish()` to get a
/// [`glib::Bytes`][crate::glib::Bytes] with the response body.
///
/// See [`send()`][Self::send()] for more details on the general semantics.
/// ## `msg`
/// a #SoupMessage
/// ## `io_priority`
/// the I/O priority of the request
/// ## `cancellable`
/// a #GCancellable
/// ## `callback`
/// the callback to invoke
#[doc(alias = "soup_session_send_and_read_async")]
fn send_and_read_async<P: FnOnce(Result<glib::Bytes, glib::Error>) + 'static>(
&self,
msg: &Message,
io_priority: glib::Priority,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn send_and_read_async_trampoline<
P: FnOnce(Result<glib::Bytes, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let ret =
ffi::soup_session_send_and_read_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = send_and_read_async_trampoline::<P>;
unsafe {
ffi::soup_session_send_and_read_async(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
io_priority.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
fn send_and_read_future(
&self,
msg: &Message,
io_priority: glib::Priority,
) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Bytes, glib::Error>> + 'static>>
{
let msg = msg.clone();
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.send_and_read_async(&msg, io_priority, Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
/// Synchronously sends @msg and splices the response body stream into @out_stream.
///
/// See [`send()`][Self::send()] for more details on the general semantics.
/// ## `msg`
/// a #SoupMessage
/// ## `out_stream`
/// a #GOutputStream
/// ## `flags`
/// a set of #GOutputStreamSpliceFlags
/// ## `cancellable`
/// a #GCancellable
///
/// # Returns
///
/// a #gssize containing the size of the data spliced, or -1 if an error occurred.
#[cfg(feature = "v3_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
#[doc(alias = "soup_session_send_and_splice")]
fn send_and_splice(
&self,
msg: &Message,
out_stream: &impl IsA<gio::OutputStream>,
flags: gio::OutputStreamSpliceFlags,
cancellable: Option<&impl IsA<gio::Cancellable>>,
) -> Result<isize, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::soup_session_send_and_splice(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
out_stream.as_ref().to_glib_none().0,
flags.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(ret)
} else {
Err(from_glib_full(error))
}
}
}
/// Asynchronously sends @msg and splices the response body stream into @out_stream.
/// When @callback is called, then either @msg has been sent and its response body
/// spliced, or else an error has occurred.
///
/// See [`send()`][Self::send()] for more details on the general semantics.
/// ## `msg`
/// a #SoupMessage
/// ## `out_stream`
/// a #GOutputStream
/// ## `flags`
/// a set of #GOutputStreamSpliceFlags
/// ## `io_priority`
/// the I/O priority of the request
/// ## `cancellable`
/// a #GCancellable
/// ## `callback`
/// the callback to invoke
#[cfg(feature = "v3_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
#[doc(alias = "soup_session_send_and_splice_async")]
fn send_and_splice_async<P: FnOnce(Result<isize, glib::Error>) + 'static>(
&self,
msg: &Message,
out_stream: &impl IsA<gio::OutputStream>,
flags: gio::OutputStreamSpliceFlags,
io_priority: glib::Priority,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn send_and_splice_async_trampoline<
P: FnOnce(Result<isize, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let ret =
ffi::soup_session_send_and_splice_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() {
Ok(ret)
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = send_and_splice_async_trampoline::<P>;
unsafe {
ffi::soup_session_send_and_splice_async(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
out_stream.as_ref().to_glib_none().0,
flags.into_glib(),
io_priority.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
#[cfg(feature = "v3_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
fn send_and_splice_future(
&self,
msg: &Message,
out_stream: &(impl IsA<gio::OutputStream> + Clone + 'static),
flags: gio::OutputStreamSpliceFlags,
io_priority: glib::Priority,
) -> Pin<Box_<dyn std::future::Future<Output = Result<isize, glib::Error>> + 'static>> {
let msg = msg.clone();
let out_stream = out_stream.clone();
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.send_and_splice_async(
&msg,
&out_stream,
flags,
io_priority,
Some(cancellable),
move |res| {
send.resolve(res);
},
);
}))
}
/// Asynchronously sends @msg and waits for the beginning of a response.
///
/// When @callback is called, then either @msg has been sent, and its response
/// headers received, or else an error has occurred. Call
/// `Session::send_finish()` to get a [`gio::InputStream`][crate::gio::InputStream] for reading the
/// response body.
///
/// See [`send()`][Self::send()] for more details on the general semantics.
/// ## `msg`
/// a #SoupMessage
/// ## `io_priority`
/// the I/O priority of the request
/// ## `cancellable`
/// a #GCancellable
/// ## `callback`
/// the callback to invoke
#[doc(alias = "soup_session_send_async")]
fn send_async<P: FnOnce(Result<gio::InputStream, glib::Error>) + 'static>(
&self,
msg: &Message,
io_priority: glib::Priority,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn send_async_trampoline<
P: FnOnce(Result<gio::InputStream, glib::Error>) + 'static,
>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
let mut error = std::ptr::null_mut();
let ret = ffi::soup_session_send_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
let callback = send_async_trampoline::<P>;
unsafe {
ffi::soup_session_send_async(
self.as_ref().to_glib_none().0,
msg.to_glib_none().0,
io_priority.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
fn send_future(
&self,
msg: &Message,
io_priority: glib::Priority,
) -> Pin<Box_<dyn std::future::Future<Output = Result<gio::InputStream, glib::Error>> + 'static>>
{
let msg = msg.clone();
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.send_async(&msg, io_priority, Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
/// Set the value to use for the "Accept-Language" header on [`Message`][crate::Message]s
/// sent from @self.
///
/// If @accept_language is [`None`] then no "Accept-Language" will be included in
/// requests. See [`accept-language`][struct@crate::Session#accept-language] for more information.
/// ## `accept_language`
/// the languages string
#[doc(alias = "soup_session_set_accept_language")]
fn set_accept_language(&self, accept_language: &str) {
unsafe {
ffi::soup_session_set_accept_language(
self.as_ref().to_glib_none().0,
accept_language.to_glib_none().0,
);
}
}
/// Set whether @self will automatically set the "Accept-Language" header on
/// requests using a value generated from system languages based on
/// `get_language_names()`.
///
/// See [`accept-language-auto`][struct@crate::Session#accept-language-auto] for more information.
/// ## `accept_language_auto`
/// the value to set
#[doc(alias = "soup_session_set_accept_language_auto")]
fn set_accept_language_auto(&self, accept_language_auto: bool) {
unsafe {
ffi::soup_session_set_accept_language_auto(
self.as_ref().to_glib_none().0,
accept_language_auto.into_glib(),
);
}
}
/// Set a timeout in seconds for idle connection lifetime to be used by @self
/// on new connections.
///
/// See [`idle-timeout`][struct@crate::Session#idle-timeout] for more information.
/// ## `timeout`
/// a timeout in seconds
#[doc(alias = "soup_session_set_idle_timeout")]
fn set_idle_timeout(&self, timeout: u32) {
unsafe {
ffi::soup_session_set_idle_timeout(self.as_ref().to_glib_none().0, timeout);
}
}
/// Set a [`gio::ProxyResolver`][crate::gio::ProxyResolver] to be used by @self on new connections.
///
/// If @proxy_resolver is [`None`] then no proxies will be used. See
/// [`proxy-resolver`][struct@crate::Session#proxy-resolver] for more information.
/// ## `proxy_resolver`
/// a #GProxyResolver or [`None`]
#[doc(alias = "soup_session_set_proxy_resolver")]
fn set_proxy_resolver(&self, proxy_resolver: Option<&impl IsA<gio::ProxyResolver>>) {
unsafe {
ffi::soup_session_set_proxy_resolver(
self.as_ref().to_glib_none().0,
proxy_resolver.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Set a timeout in seconds for socket I/O operations to be used by @self
/// on new connections.
///
/// See [`timeout`][struct@crate::Session#timeout] for more information.
/// ## `timeout`
/// a timeout in seconds
#[doc(alias = "soup_session_set_timeout")]
fn set_timeout(&self, timeout: u32) {
unsafe {
ffi::soup_session_set_timeout(self.as_ref().to_glib_none().0, timeout);
}
}
/// Set a `GIo::TlsDatabase` to be used by @self on new connections.
///
/// If @tls_database is [`None`] then certificate validation will always fail. See
/// [`tls-database`][struct@crate::Session#tls-database] for more information.
/// ## `tls_database`
/// a #GTlsDatabase
#[doc(alias = "soup_session_set_tls_database")]
fn set_tls_database(&self, tls_database: Option<&impl IsA<gio::TlsDatabase>>) {
unsafe {
ffi::soup_session_set_tls_database(
self.as_ref().to_glib_none().0,
tls_database.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Set a [`gio::TlsInteraction`][crate::gio::TlsInteraction] to be used by @self on new connections.
///
/// If @tls_interaction is [`None`] then client certificate validation will always
/// fail.
///
/// See [`tls-interaction`][struct@crate::Session#tls-interaction] for more information.
/// ## `tls_interaction`
/// a #GTlsInteraction
#[doc(alias = "soup_session_set_tls_interaction")]
fn set_tls_interaction(&self, tls_interaction: Option<&impl IsA<gio::TlsInteraction>>) {
unsafe {
ffi::soup_session_set_tls_interaction(
self.as_ref().to_glib_none().0,
tls_interaction.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Set the value to use for the "User-Agent" header on [`Message`][crate::Message]s sent
/// from @self.
///
/// If @user_agent has trailing whitespace, @self will append its own product
/// token (eg, `libsoup/3.0.0`) to the end of the header for you. If @user_agent
/// is [`None`] then no "User-Agent" will be included in requests. See
/// [`user-agent`][struct@crate::Session#user-agent] for more information.
/// ## `user_agent`
/// the user agent string
#[doc(alias = "soup_session_set_user_agent")]
fn set_user_agent(&self, user_agent: &str) {
unsafe {
ffi::soup_session_set_user_agent(
self.as_ref().to_glib_none().0,
user_agent.to_glib_none().0,
);
}
}
/// Emitted when a request is queued on @session.
///
/// When sending a request, first [`request-queued`][struct@crate::Session#request-queued]
/// is emitted, indicating that the session has become aware of
/// the request.
///
/// After a connection is available to send the request various
/// [`Message`][crate::Message] signals are emitted as the message is
/// processed. If the message is requeued, it will emit
/// [`restarted`][struct@crate::Message#restarted], which will then be followed by other
/// [`Message`][crate::Message] signals when the message is re-sent.
///
/// Eventually, the message will emit [`finished`][struct@crate::Message#finished].
/// Normally, this signals the completion of message
/// processing. However, it is possible that the application
/// will requeue the message from the "finished" handler.
/// In that case the process will loop back.
///
/// Eventually, a message will reach "finished" and not be
/// requeued. At that point, the session will emit
/// [`request-unqueued`][struct@crate::Session#request-unqueued] to indicate that it is done
/// with the message.
///
/// To sum up: [`request-queued`][struct@crate::Session#request-queued] and
/// [`request-unqueued`][struct@crate::Session#request-unqueued] are guaranteed to be emitted
/// exactly once, but [`finished`][struct@crate::Message#finished] (and all of the other
/// [`Message`][crate::Message] signals) may be invoked multiple times for a given
/// message.
/// ## `msg`
/// the request that was queued
#[doc(alias = "request-queued")]
fn connect_request_queued<F: Fn(&Self, &Message) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn request_queued_trampoline<
P: IsA<Session>,
F: Fn(&P, &Message) + 'static,
>(
this: *mut ffi::SoupSession,
msg: *mut ffi::SoupMessage,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
Session::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(msg),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"request-queued\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
request_queued_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// Emitted when a request is removed from @session's queue,
/// indicating that @session is done with it.
///
/// See [`request-queued`][struct@crate::Session#request-queued] for a detailed description of
/// the message lifecycle within a session.
/// ## `msg`
/// the request that was unqueued
#[doc(alias = "request-unqueued")]
fn connect_request_unqueued<F: Fn(&Self, &Message) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn request_unqueued_trampoline<
P: IsA<Session>,
F: Fn(&P, &Message) + 'static,
>(
this: *mut ffi::SoupSession,
msg: *mut ffi::SoupMessage,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
Session::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(msg),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"request-unqueued\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
request_unqueued_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "accept-language")]
fn connect_accept_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_accept_language_trampoline<
P: IsA<Session>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupSession,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Session::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::accept-language\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_accept_language_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "accept-language-auto")]
fn connect_accept_language_auto_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_accept_language_auto_trampoline<
P: IsA<Session>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupSession,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Session::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::accept-language-auto\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_accept_language_auto_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "idle-timeout")]
fn connect_idle_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_idle_timeout_trampoline<
P: IsA<Session>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupSession,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Session::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::idle-timeout\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_idle_timeout_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "proxy-resolver")]
fn connect_proxy_resolver_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_proxy_resolver_trampoline<
P: IsA<Session>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupSession,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Session::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::proxy-resolver\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_proxy_resolver_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "timeout")]
fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_timeout_trampoline<P: IsA<Session>, F: Fn(&P) + 'static>(
this: *mut ffi::SoupSession,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Session::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::timeout\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_timeout_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "tls-database")]
fn connect_tls_database_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_tls_database_trampoline<
P: IsA<Session>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupSession,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Session::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::tls-database\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_tls_database_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "tls-interaction")]
fn connect_tls_interaction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_tls_interaction_trampoline<
P: IsA<Session>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::SoupSession,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Session::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::tls-interaction\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_tls_interaction_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "user-agent")]
fn connect_user_agent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_user_agent_trampoline<P: IsA<Session>, F: Fn(&P) + 'static>(
this: *mut ffi::SoupSession,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Session::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::user-agent\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_user_agent_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<Session>> SessionExt for O {}