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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from webkit-gir-files
// DO NOT EDIT

use crate::ffi;
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// Represents an URI response.
    ///
    /// A #WebKitURIResponse contains information such as the URI, the
    /// status code, the content length, the mime type, the HTTP status or
    /// the suggested filename.
    ///
    /// ## Properties
    ///
    ///
    /// #### `content-length`
    ///  The expected content length of the response.
    ///
    /// Readable
    ///
    ///
    /// #### `http-headers`
    ///  The HTTP headers of the response, or [`None`] if the response is not an HTTP response.
    ///
    /// Readable
    ///
    ///
    /// #### `mime-type`
    ///  The MIME type of the response.
    ///
    /// Readable
    ///
    ///
    /// #### `status-code`
    ///  The status code of the response as returned by the server.
    ///
    /// Readable
    ///
    ///
    /// #### `suggested-filename`
    ///  The suggested filename for the URI response.
    ///
    /// Readable
    ///
    ///
    /// #### `uri`
    ///  The URI for which the response was made.
    ///
    /// Readable
    #[doc(alias = "WebKitURIResponse")]
    pub struct URIResponse(Object<ffi::WebKitURIResponse, ffi::WebKitURIResponseClass>);

    match fn {
        type_ => || ffi::webkit_uri_response_get_type(),
    }
}

impl URIResponse {
    /// Get the expected content length of the #WebKitURIResponse.
    ///
    /// It can be 0 if the server provided an incorrect or missing Content-Length.
    ///
    /// # Returns
    ///
    /// the expected content length of @self.
    #[doc(alias = "webkit_uri_response_get_content_length")]
    #[doc(alias = "get_content_length")]
    #[doc(alias = "content-length")]
    pub fn content_length(&self) -> u64 {
        unsafe { ffi::webkit_uri_response_get_content_length(self.to_glib_none().0) }
    }

    /// Get the HTTP headers of a #WebKitURIResponse as a #SoupMessageHeaders.
    ///
    /// # Returns
    ///
    /// a #SoupMessageHeaders with the HTTP headers of @self
    ///    or [`None`] if @self is not an HTTP response.
    #[doc(alias = "webkit_uri_response_get_http_headers")]
    #[doc(alias = "get_http_headers")]
    #[doc(alias = "http-headers")]
    pub fn http_headers(&self) -> Option<soup::MessageHeaders> {
        unsafe {
            from_glib_none(ffi::webkit_uri_response_get_http_headers(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the MIME type of the response.
    ///
    /// # Returns
    ///
    /// MIME type, as a string.
    #[doc(alias = "webkit_uri_response_get_mime_type")]
    #[doc(alias = "get_mime_type")]
    #[doc(alias = "mime-type")]
    pub fn mime_type(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_uri_response_get_mime_type(
                self.to_glib_none().0,
            ))
        }
    }

    /// Get the status code of the #WebKitURIResponse.
    ///
    /// Get the status code of the #WebKitURIResponse as returned by
    /// the server. It will normally be a #SoupKnownStatusCode, for
    /// example `SOUP_STATUS_OK`, though the server can respond with any
    /// unsigned integer.
    ///
    /// # Returns
    ///
    /// the status code of @self
    #[doc(alias = "webkit_uri_response_get_status_code")]
    #[doc(alias = "get_status_code")]
    #[doc(alias = "status-code")]
    pub fn status_code(&self) -> u32 {
        unsafe { ffi::webkit_uri_response_get_status_code(self.to_glib_none().0) }
    }

    /// Get the suggested filename for @self.
    ///
    /// Get the suggested filename for @self, as specified by
    /// the 'Content-Disposition' HTTP header, or [`None`] if it's not
    /// present.
    ///
    /// # Returns
    ///
    /// the suggested filename or [`None`] if
    ///    the 'Content-Disposition' HTTP header is not present.
    #[doc(alias = "webkit_uri_response_get_suggested_filename")]
    #[doc(alias = "get_suggested_filename")]
    #[doc(alias = "suggested-filename")]
    pub fn suggested_filename(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_uri_response_get_suggested_filename(
                self.to_glib_none().0,
            ))
        }
    }

    /// Gets the URI which resulted in the response.
    ///
    /// # Returns
    ///
    /// response URI, as a string.
    #[doc(alias = "webkit_uri_response_get_uri")]
    #[doc(alias = "get_uri")]
    pub fn uri(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::webkit_uri_response_get_uri(self.to_glib_none().0)) }
    }

    #[doc(alias = "content-length")]
    pub fn connect_content_length_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_content_length_trampoline<F: Fn(&URIResponse) + 'static>(
            this: *mut ffi::WebKitURIResponse,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::content-length\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_content_length_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "http-headers")]
    pub fn connect_http_headers_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_http_headers_trampoline<F: Fn(&URIResponse) + 'static>(
            this: *mut ffi::WebKitURIResponse,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::http-headers\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_http_headers_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "mime-type")]
    pub fn connect_mime_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_mime_type_trampoline<F: Fn(&URIResponse) + 'static>(
            this: *mut ffi::WebKitURIResponse,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::mime-type\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_mime_type_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "status-code")]
    pub fn connect_status_code_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_status_code_trampoline<F: Fn(&URIResponse) + 'static>(
            this: *mut ffi::WebKitURIResponse,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::status-code\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_status_code_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "suggested-filename")]
    pub fn connect_suggested_filename_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_suggested_filename_trampoline<F: Fn(&URIResponse) + 'static>(
            this: *mut ffi::WebKitURIResponse,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::suggested-filename\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_suggested_filename_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "uri")]
    pub fn connect_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_uri_trampoline<F: Fn(&URIResponse) + 'static>(
            this: *mut ffi::WebKitURIResponse,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::uri\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_uri_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}