Skip to content

Commit

Permalink
[wasm][debugger] Support NO_PROXY": "localhost" in launchSettings.json (
Browse files Browse the repository at this point in the history
#88884)

* bypass proxy for local addresses.

* Using @radical suggestion

* Support "NO_PROXY": "localhost" on launchSettings.json

* Fix null pointer exception

* Adding comment.
  • Loading branch information
thaystg authored Aug 1, 2023
1 parent 1378acb commit f60757a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/DevToolsProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
Expand All @@ -29,9 +30,11 @@ internal class DevToolsProxy
public bool IsRunning => _runLoop?.IsRunning == true;
public RunLoopExitState Stopped => _runLoop?.StoppedState;

public DevToolsProxy(ILogger logger, string loggerId)
protected readonly ProxyOptions _options;
public DevToolsProxy(ProxyOptions options, ILogger logger, string loggerId)
{
_loggerId = loggerId;
_options = options;
this.logger = logger;
}

Expand Down Expand Up @@ -235,6 +238,9 @@ public async Task RunForDevTools(Uri browserUri, WebSocket ideSocket, Cancellati

ClientWebSocket browserSocket = new();
browserSocket.Options.KeepAliveInterval = Timeout.InfiniteTimeSpan;
var proxy = WebRequest.DefaultWebProxy;
if (_options is not null && _options.IgnoreProxyForLocalAddress && proxy is not null && !proxy.IsBypassed(browserUri)) //only bypass the proxy for local addresses if it is not already an exception in the OS settings
browserSocket.Options.Proxy = new WebProxy(proxy.GetProxy(browserUri), true);
await browserSocket.ConnectAsync(browserUri, cts.Token);

using var ideConn = new DevToolsDebuggerConnection(ideSocket, "ide", logger);
Expand Down
5 changes: 1 addition & 4 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ internal class MonoProxy : DevToolsProxy
public bool JustMyCode { get; private set; }
private PauseOnExceptionsKind _defaultPauseOnExceptions { get; set; }

protected readonly ProxyOptions _options;

public MonoProxy(ILogger logger, int runtimeId = 0, string loggerId = "", ProxyOptions options = null) : base(logger, loggerId)
public MonoProxy(ILogger logger, int runtimeId = 0, string loggerId = "", ProxyOptions options = null) : base(options, logger, loggerId)
{
UrlSymbolServerList = new List<string>();
RuntimeId = runtimeId;
_options = options;
_defaultPauseOnExceptions = PauseOnExceptionsKind.Unset;
JustMyCode = options?.JustMyCode ?? false;
}
Expand Down
1 change: 1 addition & 0 deletions src/mono/wasm/debugger/BrowserDebugProxy/ProxyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public int DevToolsDebugPort
}
public string? LogPath { get; set; }
public bool RunningForBlazor { get; set; }
public bool IgnoreProxyForLocalAddress { get; set; }
public bool IsFirefoxDebugging { get; set; }
public bool JustMyCode { get; set; }
}

0 comments on commit f60757a

Please sign in to comment.