1use crate::{Message, SessionFeature, WebsocketConnection, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
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 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#[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 #[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 unsafe {
386 let mut error = std::ptr::null_mut();
387 ffi::soup_session_preconnect_finish(_source_object as *mut _, res, &mut error);
388 let result = if error.is_null() {
389 Ok(())
390 } else {
391 Err(from_glib_full(error))
392 };
393 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
394 Box_::from_raw(user_data as *mut _);
395 let callback: P = callback.into_inner();
396 callback(result);
397 }
398 }
399 let callback = preconnect_async_trampoline::<P>;
400 unsafe {
401 ffi::soup_session_preconnect_async(
402 self.as_ref().to_glib_none().0,
403 msg.to_glib_none().0,
404 io_priority.into_glib(),
405 cancellable.map(|p| p.as_ref()).to_glib_none().0,
406 Some(callback),
407 Box_::into_raw(user_data) as *mut _,
408 );
409 }
410 }
411
412 fn preconnect_future(
413 &self,
414 msg: &Message,
415 io_priority: glib::Priority,
416 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
417 let msg = msg.clone();
418 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
419 obj.preconnect_async(&msg, io_priority, Some(cancellable), move |res| {
420 send.resolve(res);
421 });
422 }))
423 }
424
425 #[doc(alias = "soup_session_remove_feature")]
426 fn remove_feature(&self, feature: &impl IsA<SessionFeature>) {
427 unsafe {
428 ffi::soup_session_remove_feature(
429 self.as_ref().to_glib_none().0,
430 feature.as_ref().to_glib_none().0,
431 );
432 }
433 }
434
435 #[doc(alias = "soup_session_remove_feature_by_type")]
436 fn remove_feature_by_type(&self, feature_type: glib::types::Type) {
437 unsafe {
438 ffi::soup_session_remove_feature_by_type(
439 self.as_ref().to_glib_none().0,
440 feature_type.into_glib(),
441 );
442 }
443 }
444
445 #[doc(alias = "soup_session_send")]
446 fn send(
447 &self,
448 msg: &Message,
449 cancellable: Option<&impl IsA<gio::Cancellable>>,
450 ) -> Result<gio::InputStream, glib::Error> {
451 unsafe {
452 let mut error = std::ptr::null_mut();
453 let ret = ffi::soup_session_send(
454 self.as_ref().to_glib_none().0,
455 msg.to_glib_none().0,
456 cancellable.map(|p| p.as_ref()).to_glib_none().0,
457 &mut error,
458 );
459 if error.is_null() {
460 Ok(from_glib_full(ret))
461 } else {
462 Err(from_glib_full(error))
463 }
464 }
465 }
466
467 #[doc(alias = "soup_session_send_and_read")]
468 fn send_and_read(
469 &self,
470 msg: &Message,
471 cancellable: Option<&impl IsA<gio::Cancellable>>,
472 ) -> Result<glib::Bytes, glib::Error> {
473 unsafe {
474 let mut error = std::ptr::null_mut();
475 let ret = ffi::soup_session_send_and_read(
476 self.as_ref().to_glib_none().0,
477 msg.to_glib_none().0,
478 cancellable.map(|p| p.as_ref()).to_glib_none().0,
479 &mut error,
480 );
481 if error.is_null() {
482 Ok(from_glib_full(ret))
483 } else {
484 Err(from_glib_full(error))
485 }
486 }
487 }
488
489 #[doc(alias = "soup_session_send_and_read_async")]
490 fn send_and_read_async<P: FnOnce(Result<glib::Bytes, glib::Error>) + 'static>(
491 &self,
492 msg: &Message,
493 io_priority: glib::Priority,
494 cancellable: Option<&impl IsA<gio::Cancellable>>,
495 callback: P,
496 ) {
497 let main_context = glib::MainContext::ref_thread_default();
498 let is_main_context_owner = main_context.is_owner();
499 let has_acquired_main_context = (!is_main_context_owner)
500 .then(|| main_context.acquire().ok())
501 .flatten();
502 assert!(
503 is_main_context_owner || has_acquired_main_context.is_some(),
504 "Async operations only allowed if the thread is owning the MainContext"
505 );
506
507 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
508 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
509 unsafe extern "C" fn send_and_read_async_trampoline<
510 P: FnOnce(Result<glib::Bytes, glib::Error>) + 'static,
511 >(
512 _source_object: *mut glib::gobject_ffi::GObject,
513 res: *mut gio::ffi::GAsyncResult,
514 user_data: glib::ffi::gpointer,
515 ) {
516 unsafe {
517 let mut error = std::ptr::null_mut();
518 let ret = ffi::soup_session_send_and_read_finish(
519 _source_object as *mut _,
520 res,
521 &mut error,
522 );
523 let result = if error.is_null() {
524 Ok(from_glib_full(ret))
525 } else {
526 Err(from_glib_full(error))
527 };
528 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
529 Box_::from_raw(user_data as *mut _);
530 let callback: P = callback.into_inner();
531 callback(result);
532 }
533 }
534 let callback = send_and_read_async_trampoline::<P>;
535 unsafe {
536 ffi::soup_session_send_and_read_async(
537 self.as_ref().to_glib_none().0,
538 msg.to_glib_none().0,
539 io_priority.into_glib(),
540 cancellable.map(|p| p.as_ref()).to_glib_none().0,
541 Some(callback),
542 Box_::into_raw(user_data) as *mut _,
543 );
544 }
545 }
546
547 fn send_and_read_future(
548 &self,
549 msg: &Message,
550 io_priority: glib::Priority,
551 ) -> Pin<Box_<dyn std::future::Future<Output = Result<glib::Bytes, glib::Error>> + 'static>>
552 {
553 let msg = msg.clone();
554 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
555 obj.send_and_read_async(&msg, io_priority, Some(cancellable), move |res| {
556 send.resolve(res);
557 });
558 }))
559 }
560
561 #[cfg(feature = "v3_4")]
562 #[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
563 #[doc(alias = "soup_session_send_and_splice")]
564 fn send_and_splice(
565 &self,
566 msg: &Message,
567 out_stream: &impl IsA<gio::OutputStream>,
568 flags: gio::OutputStreamSpliceFlags,
569 cancellable: Option<&impl IsA<gio::Cancellable>>,
570 ) -> Result<isize, glib::Error> {
571 unsafe {
572 let mut error = std::ptr::null_mut();
573 let ret = ffi::soup_session_send_and_splice(
574 self.as_ref().to_glib_none().0,
575 msg.to_glib_none().0,
576 out_stream.as_ref().to_glib_none().0,
577 flags.into_glib(),
578 cancellable.map(|p| p.as_ref()).to_glib_none().0,
579 &mut error,
580 );
581 if error.is_null() {
582 Ok(ret)
583 } else {
584 Err(from_glib_full(error))
585 }
586 }
587 }
588
589 #[cfg(feature = "v3_4")]
590 #[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
591 #[doc(alias = "soup_session_send_and_splice_async")]
592 fn send_and_splice_async<P: FnOnce(Result<isize, glib::Error>) + 'static>(
593 &self,
594 msg: &Message,
595 out_stream: &impl IsA<gio::OutputStream>,
596 flags: gio::OutputStreamSpliceFlags,
597 io_priority: glib::Priority,
598 cancellable: Option<&impl IsA<gio::Cancellable>>,
599 callback: P,
600 ) {
601 let main_context = glib::MainContext::ref_thread_default();
602 let is_main_context_owner = main_context.is_owner();
603 let has_acquired_main_context = (!is_main_context_owner)
604 .then(|| main_context.acquire().ok())
605 .flatten();
606 assert!(
607 is_main_context_owner || has_acquired_main_context.is_some(),
608 "Async operations only allowed if the thread is owning the MainContext"
609 );
610
611 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
612 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
613 unsafe extern "C" fn send_and_splice_async_trampoline<
614 P: FnOnce(Result<isize, glib::Error>) + 'static,
615 >(
616 _source_object: *mut glib::gobject_ffi::GObject,
617 res: *mut gio::ffi::GAsyncResult,
618 user_data: glib::ffi::gpointer,
619 ) {
620 unsafe {
621 let mut error = std::ptr::null_mut();
622 let ret = ffi::soup_session_send_and_splice_finish(
623 _source_object as *mut _,
624 res,
625 &mut error,
626 );
627 let result = if error.is_null() {
628 Ok(ret)
629 } else {
630 Err(from_glib_full(error))
631 };
632 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
633 Box_::from_raw(user_data as *mut _);
634 let callback: P = callback.into_inner();
635 callback(result);
636 }
637 }
638 let callback = send_and_splice_async_trampoline::<P>;
639 unsafe {
640 ffi::soup_session_send_and_splice_async(
641 self.as_ref().to_glib_none().0,
642 msg.to_glib_none().0,
643 out_stream.as_ref().to_glib_none().0,
644 flags.into_glib(),
645 io_priority.into_glib(),
646 cancellable.map(|p| p.as_ref()).to_glib_none().0,
647 Some(callback),
648 Box_::into_raw(user_data) as *mut _,
649 );
650 }
651 }
652
653 #[cfg(feature = "v3_4")]
654 #[cfg_attr(docsrs, doc(cfg(feature = "v3_4")))]
655 fn send_and_splice_future(
656 &self,
657 msg: &Message,
658 out_stream: &(impl IsA<gio::OutputStream> + Clone + 'static),
659 flags: gio::OutputStreamSpliceFlags,
660 io_priority: glib::Priority,
661 ) -> Pin<Box_<dyn std::future::Future<Output = Result<isize, glib::Error>> + 'static>> {
662 let msg = msg.clone();
663 let out_stream = out_stream.clone();
664 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
665 obj.send_and_splice_async(
666 &msg,
667 &out_stream,
668 flags,
669 io_priority,
670 Some(cancellable),
671 move |res| {
672 send.resolve(res);
673 },
674 );
675 }))
676 }
677
678 #[doc(alias = "soup_session_send_async")]
679 fn send_async<P: FnOnce(Result<gio::InputStream, glib::Error>) + 'static>(
680 &self,
681 msg: &Message,
682 io_priority: glib::Priority,
683 cancellable: Option<&impl IsA<gio::Cancellable>>,
684 callback: P,
685 ) {
686 let main_context = glib::MainContext::ref_thread_default();
687 let is_main_context_owner = main_context.is_owner();
688 let has_acquired_main_context = (!is_main_context_owner)
689 .then(|| main_context.acquire().ok())
690 .flatten();
691 assert!(
692 is_main_context_owner || has_acquired_main_context.is_some(),
693 "Async operations only allowed if the thread is owning the MainContext"
694 );
695
696 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
697 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
698 unsafe extern "C" fn send_async_trampoline<
699 P: FnOnce(Result<gio::InputStream, glib::Error>) + 'static,
700 >(
701 _source_object: *mut glib::gobject_ffi::GObject,
702 res: *mut gio::ffi::GAsyncResult,
703 user_data: glib::ffi::gpointer,
704 ) {
705 unsafe {
706 let mut error = std::ptr::null_mut();
707 let ret = ffi::soup_session_send_finish(_source_object as *mut _, res, &mut error);
708 let result = if error.is_null() {
709 Ok(from_glib_full(ret))
710 } else {
711 Err(from_glib_full(error))
712 };
713 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
714 Box_::from_raw(user_data as *mut _);
715 let callback: P = callback.into_inner();
716 callback(result);
717 }
718 }
719 let callback = send_async_trampoline::<P>;
720 unsafe {
721 ffi::soup_session_send_async(
722 self.as_ref().to_glib_none().0,
723 msg.to_glib_none().0,
724 io_priority.into_glib(),
725 cancellable.map(|p| p.as_ref()).to_glib_none().0,
726 Some(callback),
727 Box_::into_raw(user_data) as *mut _,
728 );
729 }
730 }
731
732 fn send_future(
733 &self,
734 msg: &Message,
735 io_priority: glib::Priority,
736 ) -> Pin<Box_<dyn std::future::Future<Output = Result<gio::InputStream, glib::Error>> + 'static>>
737 {
738 let msg = msg.clone();
739 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
740 obj.send_async(&msg, io_priority, Some(cancellable), move |res| {
741 send.resolve(res);
742 });
743 }))
744 }
745
746 #[doc(alias = "soup_session_set_accept_language")]
747 #[doc(alias = "accept-language")]
748 fn set_accept_language(&self, accept_language: &str) {
749 unsafe {
750 ffi::soup_session_set_accept_language(
751 self.as_ref().to_glib_none().0,
752 accept_language.to_glib_none().0,
753 );
754 }
755 }
756
757 #[doc(alias = "soup_session_set_accept_language_auto")]
758 #[doc(alias = "accept-language-auto")]
759 fn set_accept_language_auto(&self, accept_language_auto: bool) {
760 unsafe {
761 ffi::soup_session_set_accept_language_auto(
762 self.as_ref().to_glib_none().0,
763 accept_language_auto.into_glib(),
764 );
765 }
766 }
767
768 #[doc(alias = "soup_session_set_idle_timeout")]
769 #[doc(alias = "idle-timeout")]
770 fn set_idle_timeout(&self, timeout: u32) {
771 unsafe {
772 ffi::soup_session_set_idle_timeout(self.as_ref().to_glib_none().0, timeout);
773 }
774 }
775
776 #[doc(alias = "soup_session_set_proxy_resolver")]
777 #[doc(alias = "proxy-resolver")]
778 fn set_proxy_resolver(&self, proxy_resolver: Option<&impl IsA<gio::ProxyResolver>>) {
779 unsafe {
780 ffi::soup_session_set_proxy_resolver(
781 self.as_ref().to_glib_none().0,
782 proxy_resolver.map(|p| p.as_ref()).to_glib_none().0,
783 );
784 }
785 }
786
787 #[doc(alias = "soup_session_set_timeout")]
788 #[doc(alias = "timeout")]
789 fn set_timeout(&self, timeout: u32) {
790 unsafe {
791 ffi::soup_session_set_timeout(self.as_ref().to_glib_none().0, timeout);
792 }
793 }
794
795 #[doc(alias = "soup_session_set_tls_database")]
796 #[doc(alias = "tls-database")]
797 fn set_tls_database(&self, tls_database: Option<&impl IsA<gio::TlsDatabase>>) {
798 unsafe {
799 ffi::soup_session_set_tls_database(
800 self.as_ref().to_glib_none().0,
801 tls_database.map(|p| p.as_ref()).to_glib_none().0,
802 );
803 }
804 }
805
806 #[doc(alias = "soup_session_set_tls_interaction")]
807 #[doc(alias = "tls-interaction")]
808 fn set_tls_interaction(&self, tls_interaction: Option<&impl IsA<gio::TlsInteraction>>) {
809 unsafe {
810 ffi::soup_session_set_tls_interaction(
811 self.as_ref().to_glib_none().0,
812 tls_interaction.map(|p| p.as_ref()).to_glib_none().0,
813 );
814 }
815 }
816
817 #[doc(alias = "soup_session_set_user_agent")]
818 #[doc(alias = "user-agent")]
819 fn set_user_agent(&self, user_agent: &str) {
820 unsafe {
821 ffi::soup_session_set_user_agent(
822 self.as_ref().to_glib_none().0,
823 user_agent.to_glib_none().0,
824 );
825 }
826 }
827
828 #[doc(alias = "request-queued")]
829 fn connect_request_queued<F: Fn(&Self, &Message) + 'static>(&self, f: F) -> SignalHandlerId {
830 unsafe extern "C" fn request_queued_trampoline<
831 P: IsA<Session>,
832 F: Fn(&P, &Message) + 'static,
833 >(
834 this: *mut ffi::SoupSession,
835 msg: *mut ffi::SoupMessage,
836 f: glib::ffi::gpointer,
837 ) {
838 unsafe {
839 let f: &F = &*(f as *const F);
840 f(
841 Session::from_glib_borrow(this).unsafe_cast_ref(),
842 &from_glib_borrow(msg),
843 )
844 }
845 }
846 unsafe {
847 let f: Box_<F> = Box_::new(f);
848 connect_raw(
849 self.as_ptr() as *mut _,
850 c"request-queued".as_ptr(),
851 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
852 request_queued_trampoline::<Self, F> as *const (),
853 )),
854 Box_::into_raw(f),
855 )
856 }
857 }
858
859 #[doc(alias = "request-unqueued")]
860 fn connect_request_unqueued<F: Fn(&Self, &Message) + 'static>(&self, f: F) -> SignalHandlerId {
861 unsafe extern "C" fn request_unqueued_trampoline<
862 P: IsA<Session>,
863 F: Fn(&P, &Message) + 'static,
864 >(
865 this: *mut ffi::SoupSession,
866 msg: *mut ffi::SoupMessage,
867 f: glib::ffi::gpointer,
868 ) {
869 unsafe {
870 let f: &F = &*(f as *const F);
871 f(
872 Session::from_glib_borrow(this).unsafe_cast_ref(),
873 &from_glib_borrow(msg),
874 )
875 }
876 }
877 unsafe {
878 let f: Box_<F> = Box_::new(f);
879 connect_raw(
880 self.as_ptr() as *mut _,
881 c"request-unqueued".as_ptr(),
882 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
883 request_unqueued_trampoline::<Self, F> as *const (),
884 )),
885 Box_::into_raw(f),
886 )
887 }
888 }
889
890 #[doc(alias = "accept-language")]
891 fn connect_accept_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
892 unsafe extern "C" fn notify_accept_language_trampoline<
893 P: IsA<Session>,
894 F: Fn(&P) + 'static,
895 >(
896 this: *mut ffi::SoupSession,
897 _param_spec: glib::ffi::gpointer,
898 f: glib::ffi::gpointer,
899 ) {
900 unsafe {
901 let f: &F = &*(f as *const F);
902 f(Session::from_glib_borrow(this).unsafe_cast_ref())
903 }
904 }
905 unsafe {
906 let f: Box_<F> = Box_::new(f);
907 connect_raw(
908 self.as_ptr() as *mut _,
909 c"notify::accept-language".as_ptr(),
910 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
911 notify_accept_language_trampoline::<Self, F> as *const (),
912 )),
913 Box_::into_raw(f),
914 )
915 }
916 }
917
918 #[doc(alias = "accept-language-auto")]
919 fn connect_accept_language_auto_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
920 unsafe extern "C" fn notify_accept_language_auto_trampoline<
921 P: IsA<Session>,
922 F: Fn(&P) + 'static,
923 >(
924 this: *mut ffi::SoupSession,
925 _param_spec: glib::ffi::gpointer,
926 f: glib::ffi::gpointer,
927 ) {
928 unsafe {
929 let f: &F = &*(f as *const F);
930 f(Session::from_glib_borrow(this).unsafe_cast_ref())
931 }
932 }
933 unsafe {
934 let f: Box_<F> = Box_::new(f);
935 connect_raw(
936 self.as_ptr() as *mut _,
937 c"notify::accept-language-auto".as_ptr(),
938 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
939 notify_accept_language_auto_trampoline::<Self, F> as *const (),
940 )),
941 Box_::into_raw(f),
942 )
943 }
944 }
945
946 #[doc(alias = "idle-timeout")]
947 fn connect_idle_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
948 unsafe extern "C" fn notify_idle_timeout_trampoline<
949 P: IsA<Session>,
950 F: Fn(&P) + 'static,
951 >(
952 this: *mut ffi::SoupSession,
953 _param_spec: glib::ffi::gpointer,
954 f: glib::ffi::gpointer,
955 ) {
956 unsafe {
957 let f: &F = &*(f as *const F);
958 f(Session::from_glib_borrow(this).unsafe_cast_ref())
959 }
960 }
961 unsafe {
962 let f: Box_<F> = Box_::new(f);
963 connect_raw(
964 self.as_ptr() as *mut _,
965 c"notify::idle-timeout".as_ptr(),
966 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
967 notify_idle_timeout_trampoline::<Self, F> as *const (),
968 )),
969 Box_::into_raw(f),
970 )
971 }
972 }
973
974 #[doc(alias = "proxy-resolver")]
975 fn connect_proxy_resolver_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
976 unsafe extern "C" fn notify_proxy_resolver_trampoline<
977 P: IsA<Session>,
978 F: Fn(&P) + 'static,
979 >(
980 this: *mut ffi::SoupSession,
981 _param_spec: glib::ffi::gpointer,
982 f: glib::ffi::gpointer,
983 ) {
984 unsafe {
985 let f: &F = &*(f as *const F);
986 f(Session::from_glib_borrow(this).unsafe_cast_ref())
987 }
988 }
989 unsafe {
990 let f: Box_<F> = Box_::new(f);
991 connect_raw(
992 self.as_ptr() as *mut _,
993 c"notify::proxy-resolver".as_ptr(),
994 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
995 notify_proxy_resolver_trampoline::<Self, F> as *const (),
996 )),
997 Box_::into_raw(f),
998 )
999 }
1000 }
1001
1002 #[doc(alias = "timeout")]
1003 fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1004 unsafe extern "C" fn notify_timeout_trampoline<P: IsA<Session>, F: Fn(&P) + 'static>(
1005 this: *mut ffi::SoupSession,
1006 _param_spec: glib::ffi::gpointer,
1007 f: glib::ffi::gpointer,
1008 ) {
1009 unsafe {
1010 let f: &F = &*(f as *const F);
1011 f(Session::from_glib_borrow(this).unsafe_cast_ref())
1012 }
1013 }
1014 unsafe {
1015 let f: Box_<F> = Box_::new(f);
1016 connect_raw(
1017 self.as_ptr() as *mut _,
1018 c"notify::timeout".as_ptr(),
1019 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1020 notify_timeout_trampoline::<Self, F> as *const (),
1021 )),
1022 Box_::into_raw(f),
1023 )
1024 }
1025 }
1026
1027 #[doc(alias = "tls-database")]
1028 fn connect_tls_database_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1029 unsafe extern "C" fn notify_tls_database_trampoline<
1030 P: IsA<Session>,
1031 F: Fn(&P) + 'static,
1032 >(
1033 this: *mut ffi::SoupSession,
1034 _param_spec: glib::ffi::gpointer,
1035 f: glib::ffi::gpointer,
1036 ) {
1037 unsafe {
1038 let f: &F = &*(f as *const F);
1039 f(Session::from_glib_borrow(this).unsafe_cast_ref())
1040 }
1041 }
1042 unsafe {
1043 let f: Box_<F> = Box_::new(f);
1044 connect_raw(
1045 self.as_ptr() as *mut _,
1046 c"notify::tls-database".as_ptr(),
1047 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1048 notify_tls_database_trampoline::<Self, F> as *const (),
1049 )),
1050 Box_::into_raw(f),
1051 )
1052 }
1053 }
1054
1055 #[doc(alias = "tls-interaction")]
1056 fn connect_tls_interaction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1057 unsafe extern "C" fn notify_tls_interaction_trampoline<
1058 P: IsA<Session>,
1059 F: Fn(&P) + 'static,
1060 >(
1061 this: *mut ffi::SoupSession,
1062 _param_spec: glib::ffi::gpointer,
1063 f: glib::ffi::gpointer,
1064 ) {
1065 unsafe {
1066 let f: &F = &*(f as *const F);
1067 f(Session::from_glib_borrow(this).unsafe_cast_ref())
1068 }
1069 }
1070 unsafe {
1071 let f: Box_<F> = Box_::new(f);
1072 connect_raw(
1073 self.as_ptr() as *mut _,
1074 c"notify::tls-interaction".as_ptr(),
1075 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1076 notify_tls_interaction_trampoline::<Self, F> as *const (),
1077 )),
1078 Box_::into_raw(f),
1079 )
1080 }
1081 }
1082
1083 #[doc(alias = "user-agent")]
1084 fn connect_user_agent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1085 unsafe extern "C" fn notify_user_agent_trampoline<P: IsA<Session>, F: Fn(&P) + 'static>(
1086 this: *mut ffi::SoupSession,
1087 _param_spec: glib::ffi::gpointer,
1088 f: glib::ffi::gpointer,
1089 ) {
1090 unsafe {
1091 let f: &F = &*(f as *const F);
1092 f(Session::from_glib_borrow(this).unsafe_cast_ref())
1093 }
1094 }
1095 unsafe {
1096 let f: Box_<F> = Box_::new(f);
1097 connect_raw(
1098 self.as_ptr() as *mut _,
1099 c"notify::user-agent".as_ptr(),
1100 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1101 notify_user_agent_trampoline::<Self, F> as *const (),
1102 )),
1103 Box_::into_raw(f),
1104 )
1105 }
1106 }
1107}
1108
1109impl<O: IsA<Session>> SessionExt for O {}