This commit is contained in:
Florian Rappl
2026-09-03 16:25:47 +02:00
parent 7e8f45b16d
commit 9cb210040d
2 changed files with 25 additions and 4 deletions

View File

@@ -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

View File

@@ -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<string, string>
// 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<string, string>
{
["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;
}
}