Skip to content

Commit 9cb2100

Browse files
committed
Fixed #1105
1 parent 7e8f45b commit 9cb2100

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎Changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## ElectronNET.Core
44

55
- Updated dependencies
6+
- Fixed socket bridge connection when a system proxy is configured (#1105)
67
- Fixed cross-compilation behavior on same platform (#1098) @epsnm
78
- Fixed resolution of unrelated target (#1099) @epsnm
89
- Added target framework customization (#1095) @epsnm

‎src/ElectronNET.API/Bridge/SocketIOConnection.cs‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace ElectronNET.API;
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Net;
78
using System.Threading.Tasks;
89
using ElectronNET.API.Serialization;
910
using SocketIO.Serializer.SystemTextJson;
@@ -18,13 +19,21 @@ internal class SocketIOConnection : ISocketConnection
1819

1920
public SocketIOConnection(string uri, string authorization)
2021
{
21-
var opts = string.IsNullOrEmpty(authorization) ? new SocketIOOptions() : new SocketIOOptions
22+
var opts = new SocketIOOptions
2223
{
23-
ExtraHeaders = new Dictionary<string, string>
24+
// The bridge is a loopback IPC channel, so it must never go through a
25+
// (system) proxy - otherwise the handshake never reaches the socket server.
26+
Proxy = DirectProxy.Instance,
27+
};
28+
29+
if (!string.IsNullOrEmpty(authorization))
30+
{
31+
opts.ExtraHeaders = new Dictionary<string, string>
2432
{
2533
["authorization"] = authorization
26-
},
27-
};
34+
};
35+
}
36+
2837
_socket = new SocketIO(uri, opts);
2938
_socket.Serializer = new SystemTextJsonSerializer(ElectronJson.Options);
3039
// Use default System.Text.Json serializer from SocketIOClient.
@@ -152,4 +161,15 @@ private void CheckDisposed()
152161
throw new ObjectDisposedException(nameof(SocketIOConnection));
153162
}
154163
}
164+
165+
private sealed class DirectProxy : IWebProxy
166+
{
167+
public static readonly DirectProxy Instance = new DirectProxy();
168+
169+
public ICredentials Credentials { get; set; }
170+
171+
public Uri GetProxy(Uri destination) => destination;
172+
173+
public bool IsBypassed(Uri host) => true;
174+
}
155175
}

0 commit comments

Comments
 (0)