1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use glib::translate::*;
use glib::{GString, IntoGStr, IntoOptionalGStr};
use std::collections::HashMap;
use std::ptr;

use crate::MessageHeaders;

impl MessageHeaders {
    /// Looks up the "Content-Disposition" header in @self, parses it, and
    /// returns its value in *@disposition and *@params.
    ///
    /// @params can be [`None`] if you are only interested in the disposition-type.
    ///
    /// In HTTP, the most common use of this header is to set a
    /// disposition-type of "attachment", to suggest to the browser that a
    /// response should be saved to disk rather than displayed in the
    /// browser. If @params contains a "filename" parameter, this is a
    /// suggestion of a filename to use. (If the parameter value in the
    /// header contains an absolute or relative path, libsoup will truncate
    /// it down to just the final path component, so you do not need to
    /// test this yourself.)
    ///
    /// Content-Disposition is also used in "multipart/form-data", however
    /// this is handled automatically by [`Multipart`][crate::Multipart] and the associated
    /// form methods.
    ///
    /// # Returns
    ///
    /// [`true`] if @self contains a "Content-Disposition"
    ///   header, [`false`] if not (in which case *@disposition and *@params
    ///   will be unchanged).
    ///
    /// ## `disposition`
    /// return location for the
    ///   disposition-type, or [`None`]
    ///
    /// ## `params`
    /// return
    ///   location for the Content-Disposition parameters, or [`None`]
    #[doc(alias = "soup_message_headers_get_content_disposition")]
    pub fn content_disposition(&self) -> Option<(GString, HashMap<String, String>)> {
        let mut disposition = ptr::null_mut();
        let mut params = ptr::null_mut();
        unsafe {
            if bool::from_glib(ffi::soup_message_headers_get_content_disposition(
                mut_override(self.to_glib_none().0),
                &mut disposition,
                &mut params,
            )) {
                let params = if !params.is_null() {
                    HashMap::from_glib_full(params)
                } else {
                    HashMap::new()
                };
                Some((GString::from_glib_full(disposition), params))
            } else {
                None
            }
        }
    }

    /// Sets the "Content-Disposition" header in @self to @disposition,
    /// optionally with additional parameters specified in @params.
    ///
    /// See [`content_disposition()`][Self::content_disposition()] for a discussion
    /// of how Content-Disposition is used in HTTP.
    /// ## `disposition`
    /// the disposition-type
    /// ## `params`
    /// additional parameters
    #[doc(alias = "soup_message_headers_set_content_disposition")]
    pub fn set_content_disposition(
        &self,
        disposition: Option<impl IntoGStr>,
        params: Option<HashMap<String, String>>,
    ) {
        disposition.run_with_gstr(|disposition| unsafe {
            ffi::soup_message_headers_set_content_disposition(
                self.to_glib_none().0,
                disposition.to_glib_none().0,
                params.to_glib_none().0,
            )
        })
    }

    /// Looks up the "Content-Type" header in @self, parses it, and returns
    /// its value in *@content_type and *@params.
    ///
    /// @params can be [`None`] if you are only interested in the content type itself.
    ///
    /// # Returns
    ///
    /// a string with the value of the
    ///   "Content-Type" header or [`None`] if @self does not contain that
    ///   header or it cannot be parsed (in which case *@params will be
    ///   unchanged).
    ///
    /// ## `params`
    ///
    ///   return location for the Content-Type parameters (eg, "charset"), or
    ///   [`None`]
    #[doc(alias = "soup_message_headers_get_content_type")]
    pub fn content_type(&self) -> Option<(GString, HashMap<String, String>)> {
        let mut params = ptr::null_mut();
        unsafe {
            let content_type = ffi::soup_message_headers_get_content_type(
                mut_override(self.to_glib_none().0),
                &mut params,
            );
            if !content_type.is_null() {
                let params = if !params.is_null() {
                    HashMap::from_glib_full(params)
                } else {
                    HashMap::new()
                };
                Some((GString::from_glib_full(content_type), params))
            } else {
                None
            }
        }
    }

    /// Sets the "Content-Type" header in @self to @content_type.
    ///
    /// Accepts additional parameters specified in @params.
    /// ## `content_type`
    /// the MIME type
    /// ## `params`
    /// additional parameters
    #[doc(alias = "soup_message_headers_set_content_type")]
    pub fn set_content_type(
        &self,
        content_type: Option<impl IntoGStr>,
        params: Option<HashMap<String, String>>,
    ) {
        content_type.run_with_gstr(|content_type| unsafe {
            ffi::soup_message_headers_set_content_disposition(
                self.to_glib_none().0,
                content_type.to_glib_none().0,
                params.to_glib_none().0,
            )
        })
    }
}