1use crate::{ffi, HTTPVersion, MemoryUse, MessageBody, MessageHeaders};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "SoupServerMessage")]
16 pub struct ServerMessage(Object<ffi::SoupServerMessage, ffi::SoupServerMessageClass>);
17
18 match fn {
19 type_ => || ffi::soup_server_message_get_type(),
20 }
21}
22
23impl ServerMessage {
24 #[doc(alias = "soup_server_message_get_http_version")]
25 #[doc(alias = "get_http_version")]
26 pub fn http_version(&self) -> HTTPVersion {
27 unsafe {
28 from_glib(ffi::soup_server_message_get_http_version(
29 self.to_glib_none().0,
30 ))
31 }
32 }
33
34 #[doc(alias = "soup_server_message_get_local_address")]
35 #[doc(alias = "get_local_address")]
36 pub fn local_address(&self) -> Option<gio::SocketAddress> {
37 unsafe {
38 from_glib_none(ffi::soup_server_message_get_local_address(
39 self.to_glib_none().0,
40 ))
41 }
42 }
43
44 #[doc(alias = "soup_server_message_get_method")]
45 #[doc(alias = "get_method")]
46 pub fn method(&self) -> Option<glib::GString> {
47 unsafe { from_glib_none(ffi::soup_server_message_get_method(self.to_glib_none().0)) }
48 }
49
50 #[doc(alias = "soup_server_message_get_reason_phrase")]
51 #[doc(alias = "get_reason_phrase")]
52 pub fn reason_phrase(&self) -> Option<glib::GString> {
53 unsafe {
54 from_glib_none(ffi::soup_server_message_get_reason_phrase(
55 self.to_glib_none().0,
56 ))
57 }
58 }
59
60 #[doc(alias = "soup_server_message_get_remote_address")]
61 #[doc(alias = "get_remote_address")]
62 pub fn remote_address(&self) -> Option<gio::SocketAddress> {
63 unsafe {
64 from_glib_none(ffi::soup_server_message_get_remote_address(
65 self.to_glib_none().0,
66 ))
67 }
68 }
69
70 #[doc(alias = "soup_server_message_get_remote_host")]
71 #[doc(alias = "get_remote_host")]
72 pub fn remote_host(&self) -> Option<glib::GString> {
73 unsafe {
74 from_glib_none(ffi::soup_server_message_get_remote_host(
75 self.to_glib_none().0,
76 ))
77 }
78 }
79
80 #[doc(alias = "soup_server_message_get_request_body")]
81 #[doc(alias = "get_request_body")]
82 pub fn request_body(&self) -> Option<MessageBody> {
83 unsafe {
84 from_glib_none(ffi::soup_server_message_get_request_body(
85 self.to_glib_none().0,
86 ))
87 }
88 }
89
90 #[doc(alias = "soup_server_message_get_request_headers")]
91 #[doc(alias = "get_request_headers")]
92 pub fn request_headers(&self) -> Option<MessageHeaders> {
93 unsafe {
94 from_glib_none(ffi::soup_server_message_get_request_headers(
95 self.to_glib_none().0,
96 ))
97 }
98 }
99
100 #[doc(alias = "soup_server_message_get_response_body")]
101 #[doc(alias = "get_response_body")]
102 pub fn response_body(&self) -> Option<MessageBody> {
103 unsafe {
104 from_glib_none(ffi::soup_server_message_get_response_body(
105 self.to_glib_none().0,
106 ))
107 }
108 }
109
110 #[doc(alias = "soup_server_message_get_response_headers")]
111 #[doc(alias = "get_response_headers")]
112 pub fn response_headers(&self) -> Option<MessageHeaders> {
113 unsafe {
114 from_glib_none(ffi::soup_server_message_get_response_headers(
115 self.to_glib_none().0,
116 ))
117 }
118 }
119
120 #[doc(alias = "soup_server_message_get_socket")]
121 #[doc(alias = "get_socket")]
122 pub fn socket(&self) -> Option<gio::Socket> {
123 unsafe { from_glib_none(ffi::soup_server_message_get_socket(self.to_glib_none().0)) }
124 }
125
126 #[doc(alias = "soup_server_message_get_status")]
127 #[doc(alias = "get_status")]
128 pub fn status(&self) -> u32 {
129 unsafe { ffi::soup_server_message_get_status(self.to_glib_none().0) }
130 }
131
132 #[cfg(feature = "v3_2")]
133 #[cfg_attr(docsrs, doc(cfg(feature = "v3_2")))]
134 #[doc(alias = "soup_server_message_get_tls_peer_certificate")]
135 #[doc(alias = "get_tls_peer_certificate")]
136 #[doc(alias = "tls-peer-certificate")]
137 pub fn tls_peer_certificate(&self) -> Option<gio::TlsCertificate> {
138 unsafe {
139 from_glib_none(ffi::soup_server_message_get_tls_peer_certificate(
140 self.to_glib_none().0,
141 ))
142 }
143 }
144
145 #[cfg(feature = "v3_2")]
146 #[cfg_attr(docsrs, doc(cfg(feature = "v3_2")))]
147 #[doc(alias = "soup_server_message_get_tls_peer_certificate_errors")]
148 #[doc(alias = "get_tls_peer_certificate_errors")]
149 #[doc(alias = "tls-peer-certificate-errors")]
150 pub fn tls_peer_certificate_errors(&self) -> gio::TlsCertificateFlags {
151 unsafe {
152 from_glib(ffi::soup_server_message_get_tls_peer_certificate_errors(
153 self.to_glib_none().0,
154 ))
155 }
156 }
157
158 #[doc(alias = "soup_server_message_get_uri")]
159 #[doc(alias = "get_uri")]
160 pub fn uri(&self) -> Option<glib::Uri> {
161 unsafe { from_glib_none(ffi::soup_server_message_get_uri(self.to_glib_none().0)) }
162 }
163
164 #[doc(alias = "soup_server_message_is_options_ping")]
165 pub fn is_options_ping(&self) -> bool {
166 unsafe {
167 from_glib(ffi::soup_server_message_is_options_ping(
168 self.to_glib_none().0,
169 ))
170 }
171 }
172
173 #[cfg(feature = "v3_2")]
174 #[cfg_attr(docsrs, doc(cfg(feature = "v3_2")))]
175 #[doc(alias = "soup_server_message_pause")]
176 pub fn pause(&self) {
177 unsafe {
178 ffi::soup_server_message_pause(self.to_glib_none().0);
179 }
180 }
181
182 #[doc(alias = "soup_server_message_set_http_version")]
183 pub fn set_http_version(&self, version: HTTPVersion) {
184 unsafe {
185 ffi::soup_server_message_set_http_version(self.to_glib_none().0, version.into_glib());
186 }
187 }
188
189 #[doc(alias = "soup_server_message_set_redirect")]
190 pub fn set_redirect(&self, status_code: u32, redirect_uri: &str) {
191 unsafe {
192 ffi::soup_server_message_set_redirect(
193 self.to_glib_none().0,
194 status_code,
195 redirect_uri.to_glib_none().0,
196 );
197 }
198 }
199
200 #[doc(alias = "soup_server_message_set_response")]
201 pub fn set_response(&self, content_type: Option<&str>, resp_use: MemoryUse, resp_body: &[u8]) {
202 let resp_length = resp_body.len() as _;
203 unsafe {
204 ffi::soup_server_message_set_response(
205 self.to_glib_none().0,
206 content_type.to_glib_none().0,
207 resp_use.into_glib(),
208 resp_body.to_glib_none().0,
209 resp_length,
210 );
211 }
212 }
213
214 #[doc(alias = "soup_server_message_set_status")]
215 pub fn set_status(&self, status_code: u32, reason_phrase: Option<&str>) {
216 unsafe {
217 ffi::soup_server_message_set_status(
218 self.to_glib_none().0,
219 status_code,
220 reason_phrase.to_glib_none().0,
221 );
222 }
223 }
224
225 #[doc(alias = "soup_server_message_steal_connection")]
226 pub fn steal_connection(&self) -> Option<gio::IOStream> {
227 unsafe {
228 from_glib_full(ffi::soup_server_message_steal_connection(
229 self.to_glib_none().0,
230 ))
231 }
232 }
233
234 #[cfg(feature = "v3_2")]
235 #[cfg_attr(docsrs, doc(cfg(feature = "v3_2")))]
236 #[doc(alias = "soup_server_message_unpause")]
237 pub fn unpause(&self) {
238 unsafe {
239 ffi::soup_server_message_unpause(self.to_glib_none().0);
240 }
241 }
242
243 #[doc(alias = "accept-certificate")]
244 pub fn connect_accept_certificate<
245 F: Fn(&Self, &gio::TlsCertificate, gio::TlsCertificateFlags) -> bool + 'static,
246 >(
247 &self,
248 f: F,
249 ) -> SignalHandlerId {
250 unsafe extern "C" fn accept_certificate_trampoline<
251 F: Fn(&ServerMessage, &gio::TlsCertificate, gio::TlsCertificateFlags) -> bool + 'static,
252 >(
253 this: *mut ffi::SoupServerMessage,
254 tls_peer_certificate: *mut gio::ffi::GTlsCertificate,
255 tls_peer_errors: gio::ffi::GTlsCertificateFlags,
256 f: glib::ffi::gpointer,
257 ) -> glib::ffi::gboolean {
258 let f: &F = &*(f as *const F);
259 f(
260 &from_glib_borrow(this),
261 &from_glib_borrow(tls_peer_certificate),
262 from_glib(tls_peer_errors),
263 )
264 .into_glib()
265 }
266 unsafe {
267 let f: Box_<F> = Box_::new(f);
268 connect_raw(
269 self.as_ptr() as *mut _,
270 b"accept-certificate\0".as_ptr() as *const _,
271 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
272 accept_certificate_trampoline::<F> as *const (),
273 )),
274 Box_::into_raw(f),
275 )
276 }
277 }
278
279 #[doc(alias = "connected")]
280 pub fn connect_connected<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
281 unsafe extern "C" fn connected_trampoline<F: Fn(&ServerMessage) + 'static>(
282 this: *mut ffi::SoupServerMessage,
283 f: glib::ffi::gpointer,
284 ) {
285 let f: &F = &*(f as *const F);
286 f(&from_glib_borrow(this))
287 }
288 unsafe {
289 let f: Box_<F> = Box_::new(f);
290 connect_raw(
291 self.as_ptr() as *mut _,
292 b"connected\0".as_ptr() as *const _,
293 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
294 connected_trampoline::<F> as *const (),
295 )),
296 Box_::into_raw(f),
297 )
298 }
299 }
300
301 #[doc(alias = "disconnected")]
302 pub fn connect_disconnected<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
303 unsafe extern "C" fn disconnected_trampoline<F: Fn(&ServerMessage) + 'static>(
304 this: *mut ffi::SoupServerMessage,
305 f: glib::ffi::gpointer,
306 ) {
307 let f: &F = &*(f as *const F);
308 f(&from_glib_borrow(this))
309 }
310 unsafe {
311 let f: Box_<F> = Box_::new(f);
312 connect_raw(
313 self.as_ptr() as *mut _,
314 b"disconnected\0".as_ptr() as *const _,
315 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
316 disconnected_trampoline::<F> as *const (),
317 )),
318 Box_::into_raw(f),
319 )
320 }
321 }
322
323 #[doc(alias = "finished")]
324 pub fn connect_finished<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
325 unsafe extern "C" fn finished_trampoline<F: Fn(&ServerMessage) + 'static>(
326 this: *mut ffi::SoupServerMessage,
327 f: glib::ffi::gpointer,
328 ) {
329 let f: &F = &*(f as *const F);
330 f(&from_glib_borrow(this))
331 }
332 unsafe {
333 let f: Box_<F> = Box_::new(f);
334 connect_raw(
335 self.as_ptr() as *mut _,
336 b"finished\0".as_ptr() as *const _,
337 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
338 finished_trampoline::<F> as *const (),
339 )),
340 Box_::into_raw(f),
341 )
342 }
343 }
344
345 #[doc(alias = "got-body")]
346 pub fn connect_got_body<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
347 unsafe extern "C" fn got_body_trampoline<F: Fn(&ServerMessage) + 'static>(
348 this: *mut ffi::SoupServerMessage,
349 f: glib::ffi::gpointer,
350 ) {
351 let f: &F = &*(f as *const F);
352 f(&from_glib_borrow(this))
353 }
354 unsafe {
355 let f: Box_<F> = Box_::new(f);
356 connect_raw(
357 self.as_ptr() as *mut _,
358 b"got-body\0".as_ptr() as *const _,
359 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
360 got_body_trampoline::<F> as *const (),
361 )),
362 Box_::into_raw(f),
363 )
364 }
365 }
366
367 #[doc(alias = "got-chunk")]
368 pub fn connect_got_chunk<F: Fn(&Self, &glib::Bytes) + 'static>(&self, f: F) -> SignalHandlerId {
369 unsafe extern "C" fn got_chunk_trampoline<F: Fn(&ServerMessage, &glib::Bytes) + 'static>(
370 this: *mut ffi::SoupServerMessage,
371 chunk: *mut glib::ffi::GBytes,
372 f: glib::ffi::gpointer,
373 ) {
374 let f: &F = &*(f as *const F);
375 f(&from_glib_borrow(this), &from_glib_borrow(chunk))
376 }
377 unsafe {
378 let f: Box_<F> = Box_::new(f);
379 connect_raw(
380 self.as_ptr() as *mut _,
381 b"got-chunk\0".as_ptr() as *const _,
382 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
383 got_chunk_trampoline::<F> as *const (),
384 )),
385 Box_::into_raw(f),
386 )
387 }
388 }
389
390 #[doc(alias = "got-headers")]
391 pub fn connect_got_headers<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
392 unsafe extern "C" fn got_headers_trampoline<F: Fn(&ServerMessage) + 'static>(
393 this: *mut ffi::SoupServerMessage,
394 f: glib::ffi::gpointer,
395 ) {
396 let f: &F = &*(f as *const F);
397 f(&from_glib_borrow(this))
398 }
399 unsafe {
400 let f: Box_<F> = Box_::new(f);
401 connect_raw(
402 self.as_ptr() as *mut _,
403 b"got-headers\0".as_ptr() as *const _,
404 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
405 got_headers_trampoline::<F> as *const (),
406 )),
407 Box_::into_raw(f),
408 )
409 }
410 }
411
412 #[doc(alias = "wrote-body")]
413 pub fn connect_wrote_body<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
414 unsafe extern "C" fn wrote_body_trampoline<F: Fn(&ServerMessage) + 'static>(
415 this: *mut ffi::SoupServerMessage,
416 f: glib::ffi::gpointer,
417 ) {
418 let f: &F = &*(f as *const F);
419 f(&from_glib_borrow(this))
420 }
421 unsafe {
422 let f: Box_<F> = Box_::new(f);
423 connect_raw(
424 self.as_ptr() as *mut _,
425 b"wrote-body\0".as_ptr() as *const _,
426 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
427 wrote_body_trampoline::<F> as *const (),
428 )),
429 Box_::into_raw(f),
430 )
431 }
432 }
433
434 #[doc(alias = "wrote-body-data")]
435 pub fn connect_wrote_body_data<F: Fn(&Self, u32) + 'static>(&self, f: F) -> SignalHandlerId {
436 unsafe extern "C" fn wrote_body_data_trampoline<F: Fn(&ServerMessage, u32) + 'static>(
437 this: *mut ffi::SoupServerMessage,
438 chunk_size: libc::c_uint,
439 f: glib::ffi::gpointer,
440 ) {
441 let f: &F = &*(f as *const F);
442 f(&from_glib_borrow(this), chunk_size)
443 }
444 unsafe {
445 let f: Box_<F> = Box_::new(f);
446 connect_raw(
447 self.as_ptr() as *mut _,
448 b"wrote-body-data\0".as_ptr() as *const _,
449 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
450 wrote_body_data_trampoline::<F> as *const (),
451 )),
452 Box_::into_raw(f),
453 )
454 }
455 }
456
457 #[doc(alias = "wrote-chunk")]
458 pub fn connect_wrote_chunk<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
459 unsafe extern "C" fn wrote_chunk_trampoline<F: Fn(&ServerMessage) + 'static>(
460 this: *mut ffi::SoupServerMessage,
461 f: glib::ffi::gpointer,
462 ) {
463 let f: &F = &*(f as *const F);
464 f(&from_glib_borrow(this))
465 }
466 unsafe {
467 let f: Box_<F> = Box_::new(f);
468 connect_raw(
469 self.as_ptr() as *mut _,
470 b"wrote-chunk\0".as_ptr() as *const _,
471 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
472 wrote_chunk_trampoline::<F> as *const (),
473 )),
474 Box_::into_raw(f),
475 )
476 }
477 }
478
479 #[doc(alias = "wrote-headers")]
480 pub fn connect_wrote_headers<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
481 unsafe extern "C" fn wrote_headers_trampoline<F: Fn(&ServerMessage) + 'static>(
482 this: *mut ffi::SoupServerMessage,
483 f: glib::ffi::gpointer,
484 ) {
485 let f: &F = &*(f as *const F);
486 f(&from_glib_borrow(this))
487 }
488 unsafe {
489 let f: Box_<F> = Box_::new(f);
490 connect_raw(
491 self.as_ptr() as *mut _,
492 b"wrote-headers\0".as_ptr() as *const _,
493 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
494 wrote_headers_trampoline::<F> as *const (),
495 )),
496 Box_::into_raw(f),
497 )
498 }
499 }
500
501 #[doc(alias = "wrote-informational")]
502 pub fn connect_wrote_informational<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
503 unsafe extern "C" fn wrote_informational_trampoline<F: Fn(&ServerMessage) + 'static>(
504 this: *mut ffi::SoupServerMessage,
505 f: glib::ffi::gpointer,
506 ) {
507 let f: &F = &*(f as *const F);
508 f(&from_glib_borrow(this))
509 }
510 unsafe {
511 let f: Box_<F> = Box_::new(f);
512 connect_raw(
513 self.as_ptr() as *mut _,
514 b"wrote-informational\0".as_ptr() as *const _,
515 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
516 wrote_informational_trampoline::<F> as *const (),
517 )),
518 Box_::into_raw(f),
519 )
520 }
521 }
522
523 #[cfg(feature = "v3_2")]
524 #[cfg_attr(docsrs, doc(cfg(feature = "v3_2")))]
525 #[doc(alias = "tls-peer-certificate")]
526 pub fn connect_tls_peer_certificate_notify<F: Fn(&Self) + 'static>(
527 &self,
528 f: F,
529 ) -> SignalHandlerId {
530 unsafe extern "C" fn notify_tls_peer_certificate_trampoline<
531 F: Fn(&ServerMessage) + 'static,
532 >(
533 this: *mut ffi::SoupServerMessage,
534 _param_spec: glib::ffi::gpointer,
535 f: glib::ffi::gpointer,
536 ) {
537 let f: &F = &*(f as *const F);
538 f(&from_glib_borrow(this))
539 }
540 unsafe {
541 let f: Box_<F> = Box_::new(f);
542 connect_raw(
543 self.as_ptr() as *mut _,
544 b"notify::tls-peer-certificate\0".as_ptr() as *const _,
545 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
546 notify_tls_peer_certificate_trampoline::<F> as *const (),
547 )),
548 Box_::into_raw(f),
549 )
550 }
551 }
552
553 #[cfg(feature = "v3_2")]
554 #[cfg_attr(docsrs, doc(cfg(feature = "v3_2")))]
555 #[doc(alias = "tls-peer-certificate-errors")]
556 pub fn connect_tls_peer_certificate_errors_notify<F: Fn(&Self) + 'static>(
557 &self,
558 f: F,
559 ) -> SignalHandlerId {
560 unsafe extern "C" fn notify_tls_peer_certificate_errors_trampoline<
561 F: Fn(&ServerMessage) + 'static,
562 >(
563 this: *mut ffi::SoupServerMessage,
564 _param_spec: glib::ffi::gpointer,
565 f: glib::ffi::gpointer,
566 ) {
567 let f: &F = &*(f as *const F);
568 f(&from_glib_borrow(this))
569 }
570 unsafe {
571 let f: Box_<F> = Box_::new(f);
572 connect_raw(
573 self.as_ptr() as *mut _,
574 b"notify::tls-peer-certificate-errors\0".as_ptr() as *const _,
575 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
576 notify_tls_peer_certificate_errors_trampoline::<F> as *const (),
577 )),
578 Box_::into_raw(f),
579 )
580 }
581 }
582}