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