Proxy

Added in version 2.26.

class Proxy(*args, **kwargs)

A GProxy handles connecting to a remote host via a given type of proxy server. It is implemented by the gio-proxy extension point. The extensions are named after their proxy protocol name. As an example, a SOCKS5 proxy implementation can be retrieved with the name socks5 using the function get_extension_by_name.

Methods

class Proxy
connect(connection: IOStream, proxy_address: ProxyAddress, cancellable: Cancellable | None = None) IOStream

Given connection to communicate with a proxy (eg, a SocketConnection that is connected to the proxy server), this does the necessary handshake to connect to proxy_address, and if required, wraps the IOStream to handle proxy payload.

Added in version 2.26.

Parameters:
connect_async(connection: IOStream, proxy_address: ProxyAddress, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronous version of connect().

Added in version 2.26.

Parameters:
connect_finish(result: AsyncResult) IOStream

See connect().

Added in version 2.26.

Parameters:

result – a AsyncResult

get_default_for_protocol(protocol: str) Proxy | None

Find the gio-proxy extension point for a proxy implementation that supports the specified protocol.

Added in version 2.26.

Parameters:

protocol – the proxy protocol name (e.g. http, socks, etc)

supports_hostname() bool

Some proxy protocols expect to be passed a hostname, which they will resolve to an IP address themselves. Others, like SOCKS4, do not allow this. This function will return False if proxy is implementing such a protocol. When False is returned, the caller should resolve the destination hostname first, and then pass a ProxyAddress containing the stringified IP address to connect() or connect_async().

Added in version 2.26.

Virtual Methods

class Proxy
do_connect(connection: IOStream, proxy_address: ProxyAddress, cancellable: Cancellable | None = None) IOStream

Given connection to communicate with a proxy (eg, a SocketConnection that is connected to the proxy server), this does the necessary handshake to connect to proxy_address, and if required, wraps the IOStream to handle proxy payload.

Added in version 2.26.

Parameters:
do_connect_async(connection: IOStream, proxy_address: ProxyAddress, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronous version of connect().

Added in version 2.26.

Parameters:
do_connect_finish(result: AsyncResult) IOStream

See connect().

Added in version 2.26.

Parameters:

result – a AsyncResult

do_supports_hostname() bool

Some proxy protocols expect to be passed a hostname, which they will resolve to an IP address themselves. Others, like SOCKS4, do not allow this. This function will return False if proxy is implementing such a protocol. When False is returned, the caller should resolve the destination hostname first, and then pass a ProxyAddress containing the stringified IP address to connect() or connect_async().

Added in version 2.26.