Skip to content

Gio.Proxy

interface

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 IOExtensionPoint.get_extension_by_name.

Methods

connect

def connect(self, connection: IOStream, proxy_address: ProxyAddress, cancellable: Cancellable | 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.

Parameters:

connect_async

def connect_async(self, connection: IOStream, proxy_address: ProxyAddress, cancellable: Cancellable | None = ..., callback: Callable[[Proxy | None, AsyncResult], None] | None = ...) -> None

Asynchronous version of Proxy.connect.

Parameters:

connect_finish

def connect_finish(self, result: AsyncResult) -> IOStream

See Proxy.connect.

Parameters:

supports_hostname

def supports_hostname(self) -> 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 Proxy.connect or Proxy.connect_async.

Static functions

get_default_for_protocol

@staticmethod
def get_default_for_protocol(protocol: str) -> Proxy | None

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

Parameters:

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

Virtual methods

do_connect

def do_connect(self, connection: IOStream, proxy_address: ProxyAddress, cancellable: Cancellable | 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.

Parameters:

do_connect_async

def do_connect_async(self, connection: IOStream, proxy_address: ProxyAddress, cancellable: Cancellable | None = ..., callback: Callable[[Proxy | None, AsyncResult], None] | None = ...) -> None

Asynchronous version of Proxy.connect.

Parameters:

do_connect_finish

def do_connect_finish(self, result: AsyncResult) -> IOStream

See Proxy.connect.

Parameters:

do_supports_hostname

def do_supports_hostname(self) -> 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 Proxy.connect or Proxy.connect_async.