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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// from webkit2gtk-gir-files
// DO NOT EDIT

use glib::translate::*;

glib::wrapper! {
    /// Configures network proxies.
    ///
    /// WebKitNetworkProxySettings can be used to provide a custom proxy configuration
    /// to a [`WebContext`][crate::WebContext]. You need to call `webkit_web_context_set_network_proxy_settings()`
    /// with [`NetworkProxyMode::Custom`][crate::NetworkProxyMode::Custom] and a WebKitNetworkProxySettings.
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct NetworkProxySettings(Boxed<ffi::WebKitNetworkProxySettings>);

    match fn {
        copy => |ptr| ffi::webkit_network_proxy_settings_copy(mut_override(ptr)),
        free => |ptr| ffi::webkit_network_proxy_settings_free(ptr),
        type_ => || ffi::webkit_network_proxy_settings_get_type(),
    }
}

impl NetworkProxySettings {
    /// Create a new [`NetworkProxySettings`][crate::NetworkProxySettings] with the given `default_proxy_uri` and `ignore_hosts`.
    ///
    /// The default proxy URI will be used for any URI that doesn't match `ignore_hosts`, and doesn't match any
    /// of the schemes added with [`add_proxy_for_scheme()`][Self::add_proxy_for_scheme()].
    /// If `default_proxy_uri` starts with "socks://", it will be treated as referring to all three of the
    /// socks5, socks4a, and socks4 proxy types.
    ///
    /// `ignore_hosts` is a list of hostnames and IP addresses that the resolver should allow direct connections to.
    /// Entries can be in one of 4 formats:
    /// `<itemizedlist>`
    /// `<listitem>``<para>`
    /// A hostname, such as "example.com", ".example.com", or "*.example.com", any of which match "example.com" or
    /// any subdomain of it.
    /// `</para>``</listitem>`
    /// `<listitem>``<para>`
    /// An IPv4 or IPv6 address, such as "192.168.1.1", which matches only that address.
    /// `</para>``</listitem>`
    /// `<listitem>``<para>`
    /// A hostname or IP address followed by a port, such as "example.com:80", which matches whatever the hostname or IP
    /// address would match, but only for URLs with the (explicitly) indicated port. In the case of an IPv6 address, the address
    /// part must appear in brackets: "[::1]:443"
    /// `</para>``</listitem>`
    /// `<listitem>``<para>`
    /// An IP address range, given by a base address and prefix length, such as "fe80::/10", which matches any address in that range.
    /// `</para>``</listitem>`
    /// `</itemizedlist>`
    ///
    /// Note that when dealing with Unicode hostnames, the matching is done against the ASCII form of the name.
    /// Also note that hostname exclusions apply only to connections made to hosts identified by name, and IP address exclusions apply only
    /// to connections made to hosts identified by address. That is, if example.com has an address of 192.168.1.1, and `ignore_hosts`
    /// contains only "192.168.1.1", then a connection to "example.com" will use the proxy, and a connection to 192.168.1.1" will not.
    /// ## `default_proxy_uri`
    /// the default proxy URI to use, or [`None`].
    /// ## `ignore_hosts`
    /// an optional list of hosts/IP addresses to not use a proxy for.
    ///
    /// # Returns
    ///
    /// A new [`NetworkProxySettings`][crate::NetworkProxySettings].
    #[doc(alias = "webkit_network_proxy_settings_new")]
    pub fn new(default_proxy_uri: Option<&str>, ignore_hosts: &[&str]) -> NetworkProxySettings {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::webkit_network_proxy_settings_new(
                default_proxy_uri.to_glib_none().0,
                ignore_hosts.to_glib_none().0,
            ))
        }
    }

    /// Adds a URI-scheme-specific proxy.
    ///
    /// URIs whose scheme matches `uri_scheme` will be proxied via `proxy_uri`.
    /// As with the default proxy URI, if `proxy_uri` starts with "socks://", it will be treated as referring to
    /// all three of the socks5, socks4a, and socks4 proxy types.
    /// ## `scheme`
    /// the URI scheme to add a proxy for
    /// ## `proxy_uri`
    /// the proxy URI to use for `uri_scheme`
    #[doc(alias = "webkit_network_proxy_settings_add_proxy_for_scheme")]
    pub fn add_proxy_for_scheme(&mut self, scheme: &str, proxy_uri: &str) {
        unsafe {
            ffi::webkit_network_proxy_settings_add_proxy_for_scheme(
                self.to_glib_none_mut().0,
                scheme.to_glib_none().0,
                proxy_uri.to_glib_none().0,
            );
        }
    }
}