Skip to content

Commit dfd757a

Browse files
Adds printing indicator in terminal when controlling recording using web API. Closes #871 (#872)
1 parent 4bce53b commit dfd757a

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

dev-proxy/ProxyEngine.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public class ProxyEngine(IProxyConfiguration config, ISet<UrlToWatch> urlsToWatc
3333
// lists of hosts to watch extracted from urlsToWatch,
3434
// used for deciding which URLs to decrypt for further inspection
3535
private readonly ISet<UrlToWatch> _hostsToWatch = new HashSet<UrlToWatch>();
36-
private static readonly object consoleLock = new();
3736
private readonly IProxyState _proxyState = proxyState ?? throw new ArgumentNullException(nameof(proxyState));
3837
// Dictionary for plugins to store data between requests
3938
// the key is HashObject of the SessionEventArgs object
@@ -257,7 +256,6 @@ private void StartRecording()
257256
}
258257

259258
_proxyState.StartRecording();
260-
PrintRecordingIndicator(_proxyState.IsRecording);
261259
}
262260

263261
private async Task StopRecordingAsync()
@@ -267,28 +265,9 @@ private async Task StopRecordingAsync()
267265
return;
268266
}
269267

270-
PrintRecordingIndicator(false);
271268
await _proxyState.StopRecordingAsync();
272269
}
273270

274-
private static void PrintRecordingIndicator(bool isRecording)
275-
{
276-
lock (consoleLock)
277-
{
278-
if (isRecording)
279-
{
280-
Console.ForegroundColor = ConsoleColor.Red;
281-
Console.Error.Write("◉");
282-
Console.ResetColor();
283-
Console.Error.WriteLine(" Recording... ");
284-
}
285-
else
286-
{
287-
Console.Error.WriteLine("○ Stopped recording");
288-
}
289-
}
290-
}
291-
292271
// Convert strings from config to regexes.
293272
// From the list of URLs, extract host names and convert them to regexes.
294273
// We need this because before we decrypt a request, we only have access

dev-proxy/ProxyState.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Microsoft.DevProxy;
88

99
public class ProxyState : IProxyState
1010
{
11+
private static readonly object consoleLock = new object();
12+
1113
public bool IsRecording { get; private set; } = false;
1214
public List<RequestLog> RequestLogs { get; } = [];
1315
public Dictionary<string, object> GlobalData { get; } = new() {
@@ -36,6 +38,7 @@ public void StartRecording()
3638
}
3739

3840
IsRecording = true;
41+
PrintRecordingIndicator(IsRecording);
3942
}
4043

4144
public async Task StopRecordingAsync()
@@ -46,6 +49,7 @@ public async Task StopRecordingAsync()
4649
}
4750

4851
IsRecording = false;
52+
PrintRecordingIndicator(IsRecording);
4953

5054
// clone the list so that we can clear the original
5155
// list in case a new recording is started, and
@@ -68,4 +72,22 @@ public void StopProxy()
6872
{
6973
_hostApplicationLifetime.StopApplication();
7074
}
75+
76+
private void PrintRecordingIndicator(bool isRecording)
77+
{
78+
lock (consoleLock)
79+
{
80+
if (isRecording)
81+
{
82+
Console.ForegroundColor = ConsoleColor.Red;
83+
Console.Error.Write("◉");
84+
Console.ResetColor();
85+
Console.Error.WriteLine(" Recording... ");
86+
}
87+
else
88+
{
89+
Console.Error.WriteLine("○ Stopped recording");
90+
}
91+
}
92+
}
7193
}

0 commit comments

Comments
 (0)