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, aSocketConnection
that is connected to the proxy server), this does the necessary handshake to connect toproxy_address
, and if required, wraps theIOStream
to handle proxy payload.Added in version 2.26.
- Parameters:
connection – a
IOStream
proxy_address – a
ProxyAddress
cancellable – a
Cancellable
- 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:
connection – a
IOStream
proxy_address – a
ProxyAddress
cancellable – a
Cancellable
callback – a
AsyncReadyCallback
user_data – callback data
- 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
ifproxy
is implementing such a protocol. WhenFalse
is returned, the caller should resolve the destination hostname first, and then pass aProxyAddress
containing the stringified IP address toconnect()
orconnect_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, aSocketConnection
that is connected to the proxy server), this does the necessary handshake to connect toproxy_address
, and if required, wraps theIOStream
to handle proxy payload.Added in version 2.26.
- Parameters:
connection – a
IOStream
proxy_address – a
ProxyAddress
cancellable – a
Cancellable
- 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:
connection – a
IOStream
proxy_address – a
ProxyAddress
cancellable – a
Cancellable
callback – a
AsyncReadyCallback
user_data – callback data
- 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
ifproxy
is implementing such a protocol. WhenFalse
is returned, the caller should resolve the destination hostname first, and then pass aProxyAddress
containing the stringified IP address toconnect()
orconnect_async()
.Added in version 2.26.