soup/
message_headers.rs

1use glib::translate::*;
2use glib::{GString, IntoGStr, IntoOptionalGStr};
3use std::collections::HashMap;
4use std::ptr;
5
6use crate::MessageHeaders;
7
8impl MessageHeaders {
9    #[doc(alias = "soup_message_headers_get_content_disposition")]
10    pub fn content_disposition(&self) -> Option<(GString, HashMap<String, String>)> {
11        let mut disposition = ptr::null_mut();
12        let mut params = ptr::null_mut();
13        unsafe {
14            if bool::from_glib(ffi::soup_message_headers_get_content_disposition(
15                mut_override(self.to_glib_none().0),
16                &mut disposition,
17                &mut params,
18            )) {
19                let params = if !params.is_null() {
20                    HashMap::from_glib_full(params)
21                } else {
22                    HashMap::new()
23                };
24                Some((GString::from_glib_full(disposition), params))
25            } else {
26                None
27            }
28        }
29    }
30
31    #[doc(alias = "soup_message_headers_set_content_disposition")]
32    pub fn set_content_disposition(
33        &self,
34        disposition: Option<impl IntoGStr>,
35        params: Option<HashMap<String, String>>,
36    ) {
37        disposition.run_with_gstr(|disposition| unsafe {
38            ffi::soup_message_headers_set_content_disposition(
39                self.to_glib_none().0,
40                disposition.to_glib_none().0,
41                params.to_glib_none().0,
42            )
43        })
44    }
45
46    #[doc(alias = "soup_message_headers_get_content_type")]
47    pub fn content_type(&self) -> Option<(GString, HashMap<String, String>)> {
48        let mut params = ptr::null_mut();
49        unsafe {
50            let content_type = ffi::soup_message_headers_get_content_type(
51                mut_override(self.to_glib_none().0),
52                &mut params,
53            );
54            if !content_type.is_null() {
55                let params = if !params.is_null() {
56                    HashMap::from_glib_full(params)
57                } else {
58                    HashMap::new()
59                };
60                Some((GString::from_glib_full(content_type), params))
61            } else {
62                None
63            }
64        }
65    }
66
67    #[doc(alias = "soup_message_headers_set_content_type")]
68    pub fn set_content_type(
69        &self,
70        content_type: Option<impl IntoGStr>,
71        params: Option<HashMap<String, String>>,
72    ) {
73        content_type.run_with_gstr(|content_type| unsafe {
74            ffi::soup_message_headers_set_content_disposition(
75                self.to_glib_none().0,
76                content_type.to_glib_none().0,
77                params.to_glib_none().0,
78            )
79        })
80    }
81}