Skip to content

Commit 78c2c11

Browse files
committed
fix(proxy): Use noproxy for socketio as it will be always as localhost
1 parent 7a1d6ec commit 78c2c11

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/ElectronNET.API/Bridge/SocketIOConnection.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ namespace ElectronNET.API;
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Net;
8+
using System.Net.Http;
79
using System.Threading;
810
using System.Threading.Tasks;
911
using ElectronNET.API.Serialization;
1012
using Microsoft.Extensions.DependencyInjection;
1113
using SocketIOClient;
14+
using SocketIOClient.Protocol.WebSocket;
1215
using SocketIO = SocketIOClient.SocketIO;
1316
using SocketIOOptions = SocketIOClient.SocketIOOptions;
1417

@@ -39,11 +42,29 @@ public SocketIOConnection(string uri, string authorization, Action<IServiceColle
3942
_socket = new SocketIO(new Uri(uri), opts, services =>
4043
{
4144
services.AddSystemTextJson(ElectronJson.Options);
45+
46+
// Electron.NET always connects to http://localhost:{port} - a system/corporate
47+
// proxy is never meaningful here and can break the connection. Force "no proxy"
48+
// by default; apps can still override via ConfigureElectronSocketIO if they
49+
// genuinely need one (e.g. a local debugging proxy).
50+
services.AddSingleton<IWebProxy, NoProxy>();
51+
services.AddSingleton(sp => new WebSocketOptions { Proxy = sp.GetRequiredService<IWebProxy>() });
52+
services.AddSingleton(_ => new HttpClient(new HttpClientHandler { UseProxy = false }));
53+
4254
configureSocketIO?.Invoke(services);
4355
});
4456
// Outgoing args are normalized to camelCase via SerializeArg in Emit.
4557
}
4658

59+
private sealed class NoProxy : IWebProxy
60+
{
61+
public ICredentials Credentials { get; set; }
62+
63+
public Uri GetProxy(Uri destination) => destination;
64+
65+
public bool IsBypassed(Uri host) => true;
66+
}
67+
4768
public event EventHandler BridgeDisconnected;
4869

4970
public event EventHandler BridgeConnected;
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)