Proxy Resolver ignored with g_socket_client_connect_to_service
I'm working on implement the XMPP protocol in Pidgin and while trying to do some debug, I determined that the GProxyResolver
set on my GSocketClient
was being ignored. If I connect with g_socket_client_connect_to_host_async
the GProxyResolver
is used and I can see the requests in Charles Proxy which is what I'm using to debug.
I found #1989 (closed) which seemed promising, but didn't seem to fix the case of g_socket_client_connect_to_service
.
I updated the proof of concept from #1989 (closed) and can successfully connect with my proxy (Charles Proxy) not running. You should be able to run this directly and establish a TCP connection without any other setup.
import sys
from gi.repository import Gio
from gi.repository import GObject
from gi.repository import GLib
DOMAIN = 'pidginchat.com'
SERVICE = 'xmpp-client'
SOCKS_IP = '127.0.0.1'
SOCKS_PORT = 8889
SOCKS_URI = 'socks5://%s:%s' % (SOCKS_IP, SOCKS_PORT)
resolver = Gio.SimpleProxyResolver.new(SOCKS_URI, None)
print('ProxyResolver: ', resolver)
client = Gio.SocketClient.new()
client.set_proxy_resolver(resolver)
GObject.Object.connect(client, 'event', print)
con = None
def connect():
print(f'Try to connect to service {SERVICE} on {DOMAIN} via {SOCKS_IP}:{SOCKS_PORT}')
client.connect_to_service_async(DOMAIN,
SERVICE,
None,
_on_connect,
None)
def _on_connect(socket_client, result, _user_data):
global con
try:
con = socket_client.connect_finish(result)
except GLib.Error as error:
print(error)
sys.exit()
return
print(f'Successful connected to service {SERVICE} on {DOMAIN}')
print('Check SocketClient.enable-proxy": ', socket_client.props.enable_proxy)
print('Check SocketClient.proxy-resolver": ', socket_client.props.proxy_resolver)
connect()
GLib.MainLoop().run()
I didn't test g_socket_client_connect_to_uri
so that might have issues as well.
Please let me know if there is any other information you need.