soup/auto/
session.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi, Message, SessionFeature, WebsocketConnection};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::{boxed::Box as Box_, pin::Pin};
14
15glib::wrapper! {
16    #[doc(alias = "SoupSession")]
17    pub struct Session(Object<ffi::SoupSession, ffi::SoupSessionClass>);
18
19    match fn {
20        type_ => || ffi::soup_session_get_type(),
21    }
22}
23
24impl Session {
25    pub const NONE: Option<&'static Session> = None;
26
27    #[doc(alias = "soup_session_new")]
28    pub fn new() -> Session {
29        assert_initialized_main_thread!();
30        unsafe { from_glib_full(ffi::soup_session_new()) }
31    }
32
33    //#[doc(alias = "soup_session_new_with_options")]
34    //#[doc(alias = "new_with_options")]
35    //pub fn with_options(optname1: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> Session {
36    //    unsafe { TODO: call ffi:soup_session_new_with_options() }
37    //}
38
39    // rustdoc-stripper-ignore-next
40    /// Creates a new builder-pattern struct instance to construct [`Session`] objects.
41    ///
42    /// This method returns an instance of [`SessionBuilder`](crate::builders::SessionBuilder) which can be used to create [`Session`] objects.
43    pub fn builder() -> SessionBuilder {
44        SessionBuilder::new()
45    }
46}
47
48impl Default for Session {
49    fn default() -> Self {
50        Self::new()
51    }
52}
53
54// rustdoc-stripper-ignore-next
55/// A [builder-pattern] type to construct [`Session`] objects.
56///
57/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
58#[must_use = "The builder must be built to be used"]
59pub struct SessionBuilder {
60    builder: glib::object::ObjectBuilder<'static, Session>,
61}
62
63impl SessionBuilder {
64    fn new() -> Self {
65        Self {
66            builder: glib::object::Object::builder(),
67        }
68    }
69
70    pub fn accept_language(self, accept_language: impl Into<glib::GString>) -> Self {
71        Self {
72            builder: self
73                .builder
74                .property("accept-language", accept_language.into()),
75        }
76    }
77
78    pub fn accept_language_auto(self, accept_language_auto: bool) -> Self {
79        Self {
80            builder: self
81                .builder
82                .property("accept-language-auto", accept_language_auto),
83        }
84    }
85
86    pub fn idle_timeout(self, idle_timeout: u32) -> Self {
87        Self {
88            builder: self.builder.property("idle-timeout", idle_timeout),
89        }
90    }
91
92    pub fn local_address(self, local_address: &impl IsA<gio::InetSocketAddress>) -> Self {
93        Self {
94            builder: self
95                .builder
96                .property("local-address", local_address.clone().upcast()),
97        }
98    }
99
100    pub fn max_conns(self, max_conns: i32) -> Self {
101        Self {
102            builder: self.builder.property("max-conns", max_conns),
103        }
104    }
105
106    pub fn max_conns_per_host(self, max_conns_per_host: i32) -> Self {
107        Self {
108            builder: self
109                .builder
110                .property("max-conns-per-host", max_conns_per_host),
111        }
112    }
113
114    pub fn proxy_resolver(self, proxy_resolver: &impl IsA<gio::ProxyResolver>) -> Self {
115        Self {
116            builder: self
117                .builder
118                .property("proxy-resolver", proxy_resolver.clone().upcast()),
119        }
120    }
121
122    pub fn remote_connectable(self, remote_connectable: &impl IsA<gio::SocketConnectable>) -> Self {
123        Self {
124            builder: self
125                .builder
126                .property("remote-connectable", remote_connectable.clone().upcast()),
127        }
128    }
129
130    pub fn timeout(self, timeout: u32) -> Self {
131        Self {
132            builder: self.builder.property("timeout", timeout),
133        }
134    }
135
136    pub fn tls_database(self, tls_database: &impl IsA<gio::TlsDatabase>) -> Self {
137        Self {
138            builder: self
139                .builder
140                .property("tls-database", tls_database.clone().upcast()),
141        }
142    }
143
144    pub fn tls_interaction(self, tls_interaction: &impl IsA<gio::TlsInteraction>) -> Self {
145        Self {
146            builder: self
147                .builder
148                .property("tls-interaction", tls_interaction.clone().upcast()),
149        }
150    }
151
152    pub fn user_agent(self, user_agent: impl Into<glib::GString>) -> Self {
153        Self {
154            builder: self.builder.property("user-agent", user_agent.into()),
155        }
156    }
157
158    // rustdoc-stripper-ignore-next
159    /// Build the [`Session`].
160    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
161    pub fn build(self) -> Session {
162        assert_initialized_main_thread!();
163        self.builder.build()
164    }
165}
166
167pub trait SessionExt: IsA<Session> + 'static {
168    #[doc(alias = "soup_session_abort")]
169    fn abort(&self) {
170        unsafe {
171            ffi::soup_session_abort(self.as_ref().to_glib_none().0);
172        }
173    }
174
175    #[doc(alias = "soup_session_add_feature")]
176    fn add_feature(&self, feature: &impl IsA<SessionFeature>) {
177        unsafe {
178            ffi::soup_session_add_feature(
179                self.as_ref().to_glib_none().0,
180                feature.as_ref().to_glib_none().0,
181            );
182        }
183    }
184
185    #[doc(alias = "soup_session_add_feature_by_type")]
186    fn add_feature_by_type(&self, feature_type: glib::types::Type) {
187        unsafe {
188            ffi::soup_session_add_feature_by_type(
189                self.as_ref().to_glib_none().0,
190                feature_type.into_glib(),
191            );
192        }
193    }
194
195    #[doc(alias = "soup_session_get_accept_language")]
196    #[doc(alias = "get_accept_language")]
197    #[doc(alias = "accept-language")]
198    fn accept_language(&self) -> Option<glib::GString> {
199        unsafe {
200            from_glib_none(ffi::soup_session_get_accept_language(
201                self.as_ref().to_glib_none().0,
202            ))
203        }
204    }
205
206    #[doc(alias = "soup_session_get_accept_language_auto")]
207    #[doc(alias = "get_accept_language_auto")]
208    #[doc(alias = "accept-language-auto")]
209    fn accepts_language_auto(&self) -> bool {
210        unsafe {
211            from_glib(ffi::soup_session_get_accept_language_auto(
212                self.as_ref().to_glib_none().0,
213            ))
214        }
215    }
216
217    #[doc(alias = "soup_session_get_async_result_message")]
218    #[doc(alias = "get_async_result_message")]
219    fn async_result_message(&self, result: &impl IsA<gio::AsyncResult>) -> Option<Message> {
220        unsafe {
221            from_glib_none(ffi::soup_session_get_async_result_message(
222                self.as_ref().to_glib_none().0,
223                result.as_ref().to_glib_none().0,
224            ))
225        }
226    }
227
228    #[doc(alias = "soup_session_get_feature")]
229    #[doc(alias = "get_feature")]
230    fn feature(&self, feature_type: glib::types::Type) -> Option<SessionFeature> {
231        unsafe {
232            from_glib_none(ffi::soup_session_get_feature(
233                self.as_ref().to_glib_none().0,
234                feature_type.into_glib(),
235            ))
236        }
237    }
238
239    #[doc(alias = "soup_session_get_feature_for_message")]
240    #[doc(alias = "get_feature_for_message")]
241    fn feature_for_message(
242        &self,
243        feature_type: glib::types::Type,
244        msg: &Message,
245    ) -> Option<SessionFeature> {
246        unsafe {
247            from_glib_none(ffi::soup_session_get_feature_for_message(
248                self.as_ref().to_glib_none().0,
249                feature_type.into_glib(),
250                msg.to_glib_none().0,
251            ))
252        }
253    }
254
255    #[doc(alias = "soup_session_get_idle_timeout")]
256    #[doc(alias = "get_idle_timeout")]
257    #[doc(alias = "idle-timeout")]
258    fn idle_timeout(&self) -> u32 {
259        unsafe { ffi::soup_session_get_idle_timeout(self.as_ref().to_glib_none().0) }
260    }
261
262    #[doc(alias = "soup_session_get_local_address")]
263    #[doc(alias = "get_local_address")]
264    #[doc(alias = "local-address")]
265    fn local_address(&self) -> Option<gio::InetSocketAddress> {
266        unsafe {
267            from_glib_none(ffi::soup_session_get_local_address(
268                self.as_ref().to_glib_none().0,
269            ))
270        }
271    }
272
273    #[doc(alias = "soup_session_get_max_conns")]
274    #[doc(alias = "get_max_conns")]
275    #[doc(alias = "max-conns")]
276    fn max_conns(&self) -> u32 {
277        unsafe { ffi::soup_session_get_max_conns(self.as_ref().to_glib_none().0) }
278    }
279
280    #[doc(alias = "soup_session_get_max_conns_per_host")]
281    #[doc(alias = "get_max_conns_per_host")]
282    #[doc(alias = "max-conns-per-host")]
283    fn max_conns_per_host(&self) -> u32 {
284        unsafe { ffi::soup_session_get_max_conns_per_host(self.as_ref().to_glib_none().0) }
285    }
286
287    #[doc(alias = "soup_session_get_proxy_resolver")]
288    #[doc(alias = "get_proxy_resolver")]
289    #[doc(alias = "proxy-resolver")]
290    fn proxy_resolver(&self) -> Option<gio::ProxyResolver> {
291        unsafe {
292            from_glib_none(ffi::soup_session_get_proxy_resolver(
293                self.as_ref().to_glib_none().0,
294            ))
295        }
296    }
297
298    #[doc(alias = "soup_session_get_remote_connectable")]
299    #[doc(alias = "get_remote_connectable")]
300    #[doc(alias = "remote-connectable")]
301    fn remote_connectable(&self) -> Option<gio::SocketConnectable> {
302        unsafe {
303            from_glib_none(ffi::soup_session_get_remote_connectable(
304                self.as_ref().to_glib_none().0,
305            ))
306        }
307    }
308
309    #[doc(alias = "soup_session_get_timeout")]
310    #[doc(alias = "get_timeout")]
311    fn timeout(&self) -> u32 {
312        unsafe { ffi::soup_session_get_timeout(self.as_ref().to_glib_none().0) }
313    }
314
315    #[doc(alias = "soup_session_get_tls_database")]
316    #[doc(alias = "get_tls_database")]
317    #[doc(alias = "tls-database")]
318    fn tls_database(&self) -> Option<gio::TlsDatabase> {
319        unsafe {
320            from_glib_none(ffi::soup_session_get_tls_database(
321                self.as_ref().to_glib_none().0,
322            ))
323        }
324    }
325
326    #[doc(alias = "soup_session_get_tls_interaction")]
327    #[doc(alias = "get_tls_interaction")]
328    #[doc(alias = "tls-interaction")]
329    fn tls_interaction(&self) -> Option<gio::TlsInteraction> {
330        unsafe {
331            from_glib_none(ffi::soup_session_get_tls_interaction(
332                self.as_ref().to_glib_none().0,
333            ))
334        }
335    }
336
337    #[doc(alias = "soup_session_get_user_agent")]
338    #[doc(alias = "get_user_agent")]
339    #[doc(alias = "user-agent")]
340    fn user_agent(&self) -> Option<glib::GString> {
341        unsafe {
342            from_glib_none(ffi::soup_session_get_user_agent(
343                self.as_ref().to_glib_none().0,
344            ))
345        }
346    }
347
348    #[doc(alias = "soup_session_has_feature")]
349    fn has_feature(&self, feature_type: glib::types::Type) -> bool {
350        unsafe {
351            from_glib(ffi::soup_session_has_feature(
352                self.as_ref().to_glib_none().0,
353                feature_type.into_glib(),
354            ))
355        }
356    }
357
358    #[doc(alias = "soup_session_preconnect_async")]
359    fn preconnect_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
360        &self,
361        msg: &Message,
362        io_priority: glib::Priority,
363        cancellable: Option<&impl IsA<gio::Cancellable>>,
364        callback: P,
365    ) {
366        let main_context = glib::MainContext::ref_thread_default();
367        let is_main_context_owner = main_context.is_owner();
368        let has_acquired_main_context = (!is_main_context_owner)
369            .then(|| main_context.acquire().ok())
370            .flatten();
371        assert!(
372            is_main_context_owner || has_acquired_main_context.is_some(),
373            "Async operations only allowed if the thread is owning the MainContext"
374        );
375
376        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
377            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
378        unsafe extern "C" fn preconnect_async_trampoline<
379            P: FnOnce(Result<(), glib::Error>) + 'static,
380        >(
381            _source_object: *mut glib::gobject_ffi::GObject,
382            res: *mut gio::ffi::GAsyncResult,
383            user_data: glib::ffi::gpointer,
384        ) {
385            let mut error = std::ptr::null_mut();
386            ffi::soup_session_preconnect_finish(_source_object as *mut _, res, &mut error);
387            let result = if error.is_null() {
388                Ok(())
389            } else {
390                Err(from_glib_full(error))
391            };
392            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
393                Box_::from_raw(user_data as *mut _);
394            let callback: P = callback.into_inner();
395            callback(result);
396        }
397        let callback = preconnect_async_trampoline::<P>;
398        unsafe {
399            ffi::soup_session_preconnect_async(
400                self.as_ref().to_glib_none().0,
401                msg.to_glib_none().0,
402                io_priority.into_glib(),
403                cancellable.map(|p| p.as_ref()).to_glib_none().0,
404                Some(callback),
405                Box_::into_raw(user_data) as *mut _,
406            );
407        }
408    }
409
410    fn preconnect_future(
411        &self,
412        msg: &Message,
413        io_priority: glib::Priority,
414    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
415        let msg = msg.clone();
416        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
417            obj.preconnect_async(&msg, io_priority, Some(cancellable), move |res| {
418                send.resolve(res);
419            });
420        }))
421    }
422
423    #[doc(alias = "soup_session_remove_feature")]
424    fn remove_feature(&self, feature: &impl IsA<SessionFeature>) {
425        unsafe {
426            ffi::soup_session_remove_feature(
427                self.as_ref().to_glib_none().0,
428                feature.as_ref().to_glib_none().0,
429            );
430        }
431    }
432
433    #[doc(alias = "soup_session_remove_feature_by_type")]
434    fn remove_feature_by_type(&self, feature_type: glib::types::Type) {
435        unsafe {
436            ffi::soup_session_remove_feature_by_type(
437                self.as_ref().to_glib_none().0,
438                feature_type.into_glib(),
439            );
440        }
441    }
442
443    #[doc(alias = "soup_session_send")]
444    fn send(
445        &self,
446        msg: &Message,
447        cancellable: Option<&impl IsA<gio::Cancellable>>,
448    ) -> Result<gio::InputStream, glib::Error> {
449        unsafe {
450            let mut error = std::ptr::null_mut();
451            let ret = ffi::soup_session_send(
452                self.as_ref().to_glib_none().0,
453                msg.to_glib_none().0,
454                cancellable.map(|p| p.as_ref()).to_glib_none().0,
455                &mut error,
456            );
457            if error.is_null() {
458                Ok(from_glib_full(ret))
459            } else {
460                Err(from_glib_full(error))
461            }
462        }
463    }
464
465    #[doc(alias = "soup_session_send_and_read")]
466    fn send_and_read(
467        &self,
468        msg: &Message,
469        cancellable: Option<&impl IsA<gio::Cancellable>>,
470    ) -> Result<glib::Bytes, glib::Error> {
471        unsafe {
472            let mut error = std::ptr::null_mut();
473            let ret = ffi::soup_session_send_and_read(
474                self.as_ref().to_glib_none().0,
475                msg.to_glib_none().0,
476                cancellable.map(|p| p.as_ref()).to_glib_none().0,
477                &mut error,
478            );
479            if error.is_null() {
480                Ok(from_glib_full(ret))
481            } else {
482                Err(from_glib_full(error))
483            }
484        }
485    }
486
487    #[doc(alias = "soup_session_send_and_read_async")]
488    fn send_and_read_async<P: FnOnce(Result<glib::Bytes, glib::Error>) + 'static>(
489        &self,
490        msg: &Message,
491        io_priority: glib::Priority,
492        cancellable: Option<&impl IsA<gio::Cancellable>>,
493        callback: P,
494    ) {
495        let main_context = glib::MainContext::ref_thread_default();
496        let is_main_context_owner = main_context.is_owner();
497        let has_acquired_main_context = (!is_main_context_owner)
498            .then(|| main_context.acquire().ok())
499            .flatten();
500        assert!(
501            is_main_context_owner || has_acquired_main_context.is_some(),
502            "Async operations only allowed if the thread is owning the MainContext"
503        );
504
505        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
506            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
507        unsafe extern "C" fn send_and_read_async_trampoline<
508            P: FnOnce(Result<glib::Bytes, glib::Error>) + 'static,
509        >(
510            _source_object: *mut glib::gobject_ffi::GObject,
511            res: *mut gio::ffi::GAsyncResult,
512            user_data: glib::ffi::gpointer,
513        ) {
514            let mut error = std::ptr::null_mut();
515            let ret =
516                ffi::soup_session_send_and_read_finish(_source_object as *mut _, res, &mut error);
517            let result = if error.is_null() {
518                Ok(from_glib_full(ret))
519            } else {
520                Err(from_glib_full(error))
521            };
522            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
523                Box_::from_raw(user_data as *mut _);
524            let callback: P = callback.into_inner();
525            callback(result);
526        }
527        let callback = send_and_read_async_trampoline::<P>;
528        unsafe {
529            ffi::soup_session_send_and_read_async(
530                self.as_ref().to_glib_none().0,
531                msg.to_glib_none().0,
532                io_priority.into_glib(),
533                cancellable.map(|p| p.as_ref()).to_glib_none().0,
534                Some(callback),
535                Box_::into_raw(user_data) as *mut _,
536            );
537        }
538    }
539
540    fn send_and_read_future(
541        &self,
542        msg: &Message,
543        io_priority: glib::Priority,
544    ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Bytes, glib::Error>> + 'static>>
545    {
546        let msg = msg.clone();
547        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
548            obj.send_and_read_async(&msg, io_priority, Some(cancellable), move |res| {
549                send.resolve(res);
550            });
551        }))
552    }
553
554    #[cfg(feature = "v3_4")]
555    #[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
556    #[doc(alias = "soup_session_send_and_splice")]
557    fn send_and_splice(
558        &self,
559        msg: &Message,
560        out_stream: &impl IsA<gio::OutputStream>,
561        flags: gio::OutputStreamSpliceFlags,
562        cancellable: Option<&impl IsA<gio::Cancellable>>,
563    ) -> Result<isize, glib::Error> {
564        unsafe {
565            let mut error = std::ptr::null_mut();
566            let ret = ffi::soup_session_send_and_splice(
567                self.as_ref().to_glib_none().0,
568                msg.to_glib_none().0,
569                out_stream.as_ref().to_glib_none().0,
570                flags.into_glib(),
571                cancellable.map(|p| p.as_ref()).to_glib_none().0,
572                &mut error,
573            );
574            if error.is_null() {
575                Ok(ret)
576            } else {
577                Err(from_glib_full(error))
578            }
579        }
580    }
581
582    #[cfg(feature = "v3_4")]
583    #[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
584    #[doc(alias = "soup_session_send_and_splice_async")]
585    fn send_and_splice_async<P: FnOnce(Result<isize, glib::Error>) + 'static>(
586        &self,
587        msg: &Message,
588        out_stream: &impl IsA<gio::OutputStream>,
589        flags: gio::OutputStreamSpliceFlags,
590        io_priority: glib::Priority,
591        cancellable: Option<&impl IsA<gio::Cancellable>>,
592        callback: P,
593    ) {
594        let main_context = glib::MainContext::ref_thread_default();
595        let is_main_context_owner = main_context.is_owner();
596        let has_acquired_main_context = (!is_main_context_owner)
597            .then(|| main_context.acquire().ok())
598            .flatten();
599        assert!(
600            is_main_context_owner || has_acquired_main_context.is_some(),
601            "Async operations only allowed if the thread is owning the MainContext"
602        );
603
604        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
605            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
606        unsafe extern "C" fn send_and_splice_async_trampoline<
607            P: FnOnce(Result<isize, glib::Error>) + 'static,
608        >(
609            _source_object: *mut glib::gobject_ffi::GObject,
610            res: *mut gio::ffi::GAsyncResult,
611            user_data: glib::ffi::gpointer,
612        ) {
613            let mut error = std::ptr::null_mut();
614            let ret =
615                ffi::soup_session_send_and_splice_finish(_source_object as *mut _, res, &mut error);
616            let result = if error.is_null() {
617                Ok(ret)
618            } else {
619                Err(from_glib_full(error))
620            };
621            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
622                Box_::from_raw(user_data as *mut _);
623            let callback: P = callback.into_inner();
624            callback(result);
625        }
626        let callback = send_and_splice_async_trampoline::<P>;
627        unsafe {
628            ffi::soup_session_send_and_splice_async(
629                self.as_ref().to_glib_none().0,
630                msg.to_glib_none().0,
631                out_stream.as_ref().to_glib_none().0,
632                flags.into_glib(),
633                io_priority.into_glib(),
634                cancellable.map(|p| p.as_ref()).to_glib_none().0,
635                Some(callback),
636                Box_::into_raw(user_data) as *mut _,
637            );
638        }
639    }
640
641    #[cfg(feature = "v3_4")]
642    #[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
643    fn send_and_splice_future(
644        &self,
645        msg: &Message,
646        out_stream: &(impl IsA<gio::OutputStream> + Clone + 'static),
647        flags: gio::OutputStreamSpliceFlags,
648        io_priority: glib::Priority,
649    ) -> Pin<Box_<dyn std::future::Future<Output = Result<isize, glib::Error>> + 'static>> {
650        let msg = msg.clone();
651        let out_stream = out_stream.clone();
652        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
653            obj.send_and_splice_async(
654                &msg,
655                &out_stream,
656                flags,
657                io_priority,
658                Some(cancellable),
659                move |res| {
660                    send.resolve(res);
661                },
662            );
663        }))
664    }
665
666    #[doc(alias = "soup_session_send_async")]
667    fn send_async<P: FnOnce(Result<gio::InputStream, glib::Error>) + 'static>(
668        &self,
669        msg: &Message,
670        io_priority: glib::Priority,
671        cancellable: Option<&impl IsA<gio::Cancellable>>,
672        callback: P,
673    ) {
674        let main_context = glib::MainContext::ref_thread_default();
675        let is_main_context_owner = main_context.is_owner();
676        let has_acquired_main_context = (!is_main_context_owner)
677            .then(|| main_context.acquire().ok())
678            .flatten();
679        assert!(
680            is_main_context_owner || has_acquired_main_context.is_some(),
681            "Async operations only allowed if the thread is owning the MainContext"
682        );
683
684        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
685            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
686        unsafe extern "C" fn send_async_trampoline<
687            P: FnOnce(Result<gio::InputStream, glib::Error>) + 'static,
688        >(
689            _source_object: *mut glib::gobject_ffi::GObject,
690            res: *mut gio::ffi::GAsyncResult,
691            user_data: glib::ffi::gpointer,
692        ) {
693            let mut error = std::ptr::null_mut();
694            let ret = ffi::soup_session_send_finish(_source_object as *mut _, res, &mut error);
695            let result = if error.is_null() {
696                Ok(from_glib_full(ret))
697            } else {
698                Err(from_glib_full(error))
699            };
700            let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
701                Box_::from_raw(user_data as *mut _);
702            let callback: P = callback.into_inner();
703            callback(result);
704        }
705        let callback = send_async_trampoline::<P>;
706        unsafe {
707            ffi::soup_session_send_async(
708                self.as_ref().to_glib_none().0,
709                msg.to_glib_none().0,
710                io_priority.into_glib(),
711                cancellable.map(|p| p.as_ref()).to_glib_none().0,
712                Some(callback),
713                Box_::into_raw(user_data) as *mut _,
714            );
715        }
716    }
717
718    fn send_future(
719        &self,
720        msg: &Message,
721        io_priority: glib::Priority,
722    ) -> Pin<Box_<dyn std::future::Future<Output = Result<gio::InputStream, glib::Error>> + 'static>>
723    {
724        let msg = msg.clone();
725        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
726            obj.send_async(&msg, io_priority, Some(cancellable), move |res| {
727                send.resolve(res);
728            });
729        }))
730    }
731
732    #[doc(alias = "soup_session_set_accept_language")]
733    #[doc(alias = "accept-language")]
734    fn set_accept_language(&self, accept_language: &str) {
735        unsafe {
736            ffi::soup_session_set_accept_language(
737                self.as_ref().to_glib_none().0,
738                accept_language.to_glib_none().0,
739            );
740        }
741    }
742
743    #[doc(alias = "soup_session_set_accept_language_auto")]
744    #[doc(alias = "accept-language-auto")]
745    fn set_accept_language_auto(&self, accept_language_auto: bool) {
746        unsafe {
747            ffi::soup_session_set_accept_language_auto(
748                self.as_ref().to_glib_none().0,
749                accept_language_auto.into_glib(),
750            );
751        }
752    }
753
754    #[doc(alias = "soup_session_set_idle_timeout")]
755    #[doc(alias = "idle-timeout")]
756    fn set_idle_timeout(&self, timeout: u32) {
757        unsafe {
758            ffi::soup_session_set_idle_timeout(self.as_ref().to_glib_none().0, timeout);
759        }
760    }
761
762    #[doc(alias = "soup_session_set_proxy_resolver")]
763    #[doc(alias = "proxy-resolver")]
764    fn set_proxy_resolver(&self, proxy_resolver: Option<&impl IsA<gio::ProxyResolver>>) {
765        unsafe {
766            ffi::soup_session_set_proxy_resolver(
767                self.as_ref().to_glib_none().0,
768                proxy_resolver.map(|p| p.as_ref()).to_glib_none().0,
769            );
770        }
771    }
772
773    #[doc(alias = "soup_session_set_timeout")]
774    #[doc(alias = "timeout")]
775    fn set_timeout(&self, timeout: u32) {
776        unsafe {
777            ffi::soup_session_set_timeout(self.as_ref().to_glib_none().0, timeout);
778        }
779    }
780
781    #[doc(alias = "soup_session_set_tls_database")]
782    #[doc(alias = "tls-database")]
783    fn set_tls_database(&self, tls_database: Option<&impl IsA<gio::TlsDatabase>>) {
784        unsafe {
785            ffi::soup_session_set_tls_database(
786                self.as_ref().to_glib_none().0,
787                tls_database.map(|p| p.as_ref()).to_glib_none().0,
788            );
789        }
790    }
791
792    #[doc(alias = "soup_session_set_tls_interaction")]
793    #[doc(alias = "tls-interaction")]
794    fn set_tls_interaction(&self, tls_interaction: Option<&impl IsA<gio::TlsInteraction>>) {
795        unsafe {
796            ffi::soup_session_set_tls_interaction(
797                self.as_ref().to_glib_none().0,
798                tls_interaction.map(|p| p.as_ref()).to_glib_none().0,
799            );
800        }
801    }
802
803    #[doc(alias = "soup_session_set_user_agent")]
804    #[doc(alias = "user-agent")]
805    fn set_user_agent(&self, user_agent: &str) {
806        unsafe {
807            ffi::soup_session_set_user_agent(
808                self.as_ref().to_glib_none().0,
809                user_agent.to_glib_none().0,
810            );
811        }
812    }
813
814    #[doc(alias = "request-queued")]
815    fn connect_request_queued<F: Fn(&Self, &Message) + 'static>(&self, f: F) -> SignalHandlerId {
816        unsafe extern "C" fn request_queued_trampoline<
817            P: IsA<Session>,
818            F: Fn(&P, &Message) + 'static,
819        >(
820            this: *mut ffi::SoupSession,
821            msg: *mut ffi::SoupMessage,
822            f: glib::ffi::gpointer,
823        ) {
824            let f: &F = &*(f as *const F);
825            f(
826                Session::from_glib_borrow(this).unsafe_cast_ref(),
827                &from_glib_borrow(msg),
828            )
829        }
830        unsafe {
831            let f: Box_<F> = Box_::new(f);
832            connect_raw(
833                self.as_ptr() as *mut _,
834                c"request-queued".as_ptr() as *const _,
835                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
836                    request_queued_trampoline::<Self, F> as *const (),
837                )),
838                Box_::into_raw(f),
839            )
840        }
841    }
842
843    #[doc(alias = "request-unqueued")]
844    fn connect_request_unqueued<F: Fn(&Self, &Message) + 'static>(&self, f: F) -> SignalHandlerId {
845        unsafe extern "C" fn request_unqueued_trampoline<
846            P: IsA<Session>,
847            F: Fn(&P, &Message) + 'static,
848        >(
849            this: *mut ffi::SoupSession,
850            msg: *mut ffi::SoupMessage,
851            f: glib::ffi::gpointer,
852        ) {
853            let f: &F = &*(f as *const F);
854            f(
855                Session::from_glib_borrow(this).unsafe_cast_ref(),
856                &from_glib_borrow(msg),
857            )
858        }
859        unsafe {
860            let f: Box_<F> = Box_::new(f);
861            connect_raw(
862                self.as_ptr() as *mut _,
863                c"request-unqueued".as_ptr() as *const _,
864                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
865                    request_unqueued_trampoline::<Self, F> as *const (),
866                )),
867                Box_::into_raw(f),
868            )
869        }
870    }
871
872    #[doc(alias = "accept-language")]
873    fn connect_accept_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
874        unsafe extern "C" fn notify_accept_language_trampoline<
875            P: IsA<Session>,
876            F: Fn(&P) + 'static,
877        >(
878            this: *mut ffi::SoupSession,
879            _param_spec: glib::ffi::gpointer,
880            f: glib::ffi::gpointer,
881        ) {
882            let f: &F = &*(f as *const F);
883            f(Session::from_glib_borrow(this).unsafe_cast_ref())
884        }
885        unsafe {
886            let f: Box_<F> = Box_::new(f);
887            connect_raw(
888                self.as_ptr() as *mut _,
889                c"notify::accept-language".as_ptr() as *const _,
890                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
891                    notify_accept_language_trampoline::<Self, F> as *const (),
892                )),
893                Box_::into_raw(f),
894            )
895        }
896    }
897
898    #[doc(alias = "accept-language-auto")]
899    fn connect_accept_language_auto_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
900        unsafe extern "C" fn notify_accept_language_auto_trampoline<
901            P: IsA<Session>,
902            F: Fn(&P) + 'static,
903        >(
904            this: *mut ffi::SoupSession,
905            _param_spec: glib::ffi::gpointer,
906            f: glib::ffi::gpointer,
907        ) {
908            let f: &F = &*(f as *const F);
909            f(Session::from_glib_borrow(this).unsafe_cast_ref())
910        }
911        unsafe {
912            let f: Box_<F> = Box_::new(f);
913            connect_raw(
914                self.as_ptr() as *mut _,
915                c"notify::accept-language-auto".as_ptr() as *const _,
916                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
917                    notify_accept_language_auto_trampoline::<Self, F> as *const (),
918                )),
919                Box_::into_raw(f),
920            )
921        }
922    }
923
924    #[doc(alias = "idle-timeout")]
925    fn connect_idle_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
926        unsafe extern "C" fn notify_idle_timeout_trampoline<
927            P: IsA<Session>,
928            F: Fn(&P) + 'static,
929        >(
930            this: *mut ffi::SoupSession,
931            _param_spec: glib::ffi::gpointer,
932            f: glib::ffi::gpointer,
933        ) {
934            let f: &F = &*(f as *const F);
935            f(Session::from_glib_borrow(this).unsafe_cast_ref())
936        }
937        unsafe {
938            let f: Box_<F> = Box_::new(f);
939            connect_raw(
940                self.as_ptr() as *mut _,
941                c"notify::idle-timeout".as_ptr() as *const _,
942                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
943                    notify_idle_timeout_trampoline::<Self, F> as *const (),
944                )),
945                Box_::into_raw(f),
946            )
947        }
948    }
949
950    #[doc(alias = "proxy-resolver")]
951    fn connect_proxy_resolver_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
952        unsafe extern "C" fn notify_proxy_resolver_trampoline<
953            P: IsA<Session>,
954            F: Fn(&P) + 'static,
955        >(
956            this: *mut ffi::SoupSession,
957            _param_spec: glib::ffi::gpointer,
958            f: glib::ffi::gpointer,
959        ) {
960            let f: &F = &*(f as *const F);
961            f(Session::from_glib_borrow(this).unsafe_cast_ref())
962        }
963        unsafe {
964            let f: Box_<F> = Box_::new(f);
965            connect_raw(
966                self.as_ptr() as *mut _,
967                c"notify::proxy-resolver".as_ptr() as *const _,
968                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
969                    notify_proxy_resolver_trampoline::<Self, F> as *const (),
970                )),
971                Box_::into_raw(f),
972            )
973        }
974    }
975
976    #[doc(alias = "timeout")]
977    fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
978        unsafe extern "C" fn notify_timeout_trampoline<P: IsA<Session>, F: Fn(&P) + 'static>(
979            this: *mut ffi::SoupSession,
980            _param_spec: glib::ffi::gpointer,
981            f: glib::ffi::gpointer,
982        ) {
983            let f: &F = &*(f as *const F);
984            f(Session::from_glib_borrow(this).unsafe_cast_ref())
985        }
986        unsafe {
987            let f: Box_<F> = Box_::new(f);
988            connect_raw(
989                self.as_ptr() as *mut _,
990                c"notify::timeout".as_ptr() as *const _,
991                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
992                    notify_timeout_trampoline::<Self, F> as *const (),
993                )),
994                Box_::into_raw(f),
995            )
996        }
997    }
998
999    #[doc(alias = "tls-database")]
1000    fn connect_tls_database_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1001        unsafe extern "C" fn notify_tls_database_trampoline<
1002            P: IsA<Session>,
1003            F: Fn(&P) + 'static,
1004        >(
1005            this: *mut ffi::SoupSession,
1006            _param_spec: glib::ffi::gpointer,
1007            f: glib::ffi::gpointer,
1008        ) {
1009            let f: &F = &*(f as *const F);
1010            f(Session::from_glib_borrow(this).unsafe_cast_ref())
1011        }
1012        unsafe {
1013            let f: Box_<F> = Box_::new(f);
1014            connect_raw(
1015                self.as_ptr() as *mut _,
1016                c"notify::tls-database".as_ptr() as *const _,
1017                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1018                    notify_tls_database_trampoline::<Self, F> as *const (),
1019                )),
1020                Box_::into_raw(f),
1021            )
1022        }
1023    }
1024
1025    #[doc(alias = "tls-interaction")]
1026    fn connect_tls_interaction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1027        unsafe extern "C" fn notify_tls_interaction_trampoline<
1028            P: IsA<Session>,
1029            F: Fn(&P) + 'static,
1030        >(
1031            this: *mut ffi::SoupSession,
1032            _param_spec: glib::ffi::gpointer,
1033            f: glib::ffi::gpointer,
1034        ) {
1035            let f: &F = &*(f as *const F);
1036            f(Session::from_glib_borrow(this).unsafe_cast_ref())
1037        }
1038        unsafe {
1039            let f: Box_<F> = Box_::new(f);
1040            connect_raw(
1041                self.as_ptr() as *mut _,
1042                c"notify::tls-interaction".as_ptr() as *const _,
1043                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1044                    notify_tls_interaction_trampoline::<Self, F> as *const (),
1045                )),
1046                Box_::into_raw(f),
1047            )
1048        }
1049    }
1050
1051    #[doc(alias = "user-agent")]
1052    fn connect_user_agent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1053        unsafe extern "C" fn notify_user_agent_trampoline<P: IsA<Session>, F: Fn(&P) + 'static>(
1054            this: *mut ffi::SoupSession,
1055            _param_spec: glib::ffi::gpointer,
1056            f: glib::ffi::gpointer,
1057        ) {
1058            let f: &F = &*(f as *const F);
1059            f(Session::from_glib_borrow(this).unsafe_cast_ref())
1060        }
1061        unsafe {
1062            let f: Box_<F> = Box_::new(f);
1063            connect_raw(
1064                self.as_ptr() as *mut _,
1065                c"notify::user-agent".as_ptr() as *const _,
1066                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1067                    notify_user_agent_trampoline::<Self, F> as *const (),
1068                )),
1069                Box_::into_raw(f),
1070            )
1071        }
1072    }
1073}
1074
1075impl<O: IsA<Session>> SessionExt for O {}