From 9cb210040d6fac3767d7347071c35cdd7e1badf5 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 3 Sep 2026 16:25:47 +0200 Subject: [PATCH] Fixed #1105 --- Changelog.md | 1 + .../Bridge/SocketIOConnection.cs | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 977bdf7..d9f2b76 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ ## ElectronNET.Core - Updated dependencies +- Fixed socket bridge connection when a system proxy is configured (#1105) - Fixed cross-compilation behavior on same platform (#1098) @epsnm - Fixed resolution of unrelated target (#1099) @epsnm - Added target framework customization (#1095) @epsnm diff --git a/src/ElectronNET.API/Bridge/SocketIOConnection.cs b/src/ElectronNET.API/Bridge/SocketIOConnection.cs index 36ea2e5..10a88a7 100644 --- a/src/ElectronNET.API/Bridge/SocketIOConnection.cs +++ b/src/ElectronNET.API/Bridge/SocketIOConnection.cs @@ -4,6 +4,7 @@ namespace ElectronNET.API; using System; using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; using ElectronNET.API.Serialization; using SocketIO.Serializer.SystemTextJson; @@ -18,13 +19,21 @@ internal class SocketIOConnection : ISocketConnection public SocketIOConnection(string uri, string authorization) { - var opts = string.IsNullOrEmpty(authorization) ? new SocketIOOptions() : new SocketIOOptions + var opts = new SocketIOOptions { - ExtraHeaders = new Dictionary + // The bridge is a loopback IPC channel, so it must never go through a + // (system) proxy - otherwise the handshake never reaches the socket server. + Proxy = DirectProxy.Instance, + }; + + if (!string.IsNullOrEmpty(authorization)) + { + opts.ExtraHeaders = new Dictionary { ["authorization"] = authorization - }, - }; + }; + } + _socket = new SocketIO(uri, opts); _socket.Serializer = new SystemTextJsonSerializer(ElectronJson.Options); // Use default System.Text.Json serializer from SocketIOClient. @@ -152,4 +161,15 @@ internal class SocketIOConnection : ISocketConnection throw new ObjectDisposedException(nameof(SocketIOConnection)); } } + + private sealed class DirectProxy : IWebProxy + { + public static readonly DirectProxy Instance = new DirectProxy(); + + public ICredentials Credentials { get; set; } + + public Uri GetProxy(Uri destination) => destination; + + public bool IsBypassed(Uri host) => true; + } } \ No newline at end of file