diff --git a/dev-proxy-abstractions/PluginEvents.cs b/dev-proxy-abstractions/PluginEvents.cs index 6a642d3c..07ac1e36 100644 --- a/dev-proxy-abstractions/PluginEvents.cs +++ b/dev-proxy-abstractions/PluginEvents.cs @@ -187,15 +187,21 @@ public void RaiseOptionsLoaded(OptionsLoadedArgs args) { } public async Task RaiseProxyBeforeRequest(ProxyRequestArgs args) { - await BeforeRequest?.InvokeAsync(this, args, null); + if (BeforeRequest is not null) { + await BeforeRequest.InvokeAsync(this, args, null); + } } public async Task RaiseProxyBeforeResponse(ProxyResponseArgs args) { - await BeforeResponse?.InvokeAsync(this, args, null); + if (BeforeResponse is not null) { + await BeforeResponse.InvokeAsync(this, args, null); + } } public async Task RaiseProxyAfterResponse(ProxyResponseArgs args) { - await AfterResponse?.Invoke(this, args); + if (AfterResponse is not null) { + await AfterResponse.InvokeAsync(this, args, null); + } } public void RaiseRequestLogged(RequestLogArgs args) { @@ -203,6 +209,8 @@ public void RaiseRequestLogged(RequestLogArgs args) { } public async Task RaiseRecordingStopped(RecordingArgs args) { - await AfterRecordingStop?.Invoke(this, args); + if (AfterRecordingStop is not null) { + await AfterRecordingStop.InvokeAsync(this, args, null); + } } } diff --git a/dev-proxy-plugins/Inspection/WebSocketServer.cs b/dev-proxy-plugins/Inspection/WebSocketServer.cs index 354ab916..81893f5a 100644 --- a/dev-proxy-plugins/Inspection/WebSocketServer.cs +++ b/dev-proxy-plugins/Inspection/WebSocketServer.cs @@ -42,7 +42,7 @@ private async Task HandleMessages(WebSocket ws) if (result.MessageType == WebSocketMessageType.Text) { - var message = Encoding.UTF8.GetString(buffer.Array, 0, result.Count); + var message = Encoding.UTF8.GetString(buffer.Array!, 0, result.Count); MessageReceived?.Invoke(message); } } diff --git a/dev-proxy-plugins/dev-proxy-plugins.csproj b/dev-proxy-plugins/dev-proxy-plugins.csproj index b2d03f19..05ec2c7c 100644 --- a/dev-proxy-plugins/dev-proxy-plugins.csproj +++ b/dev-proxy-plugins/dev-proxy-plugins.csproj @@ -9,6 +9,9 @@ 0.13.0 false + + CS1998 + false diff --git a/dev-proxy/ProxyEngine.cs b/dev-proxy/ProxyEngine.cs index d30c73d9..3d17f53b 100644 --- a/dev-proxy/ProxyEngine.cs +++ b/dev-proxy/ProxyEngine.cs @@ -129,7 +129,7 @@ public async Task Run(CancellationToken? cancellationToken) { if (!Console.IsInputRedirected) { ReadKeys(); } - while (_proxyServer.ProxyRunning) { Thread.Sleep(10); } + while (_proxyServer.ProxyRunning) { await Task.Delay(10); } } private void AfterRequestLog(object? sender, RequestLogArgs e) { @@ -149,7 +149,8 @@ private void ReadKeys() { StartRecording(); } if (key == ConsoleKey.S) { - StopRecording(); + // we need to use GetAwaiter().GetResult() because we're in a sync method + StopRecording().GetAwaiter().GetResult(); } if (key == ConsoleKey.C) { Console.Clear(); @@ -400,7 +401,7 @@ async Task OnAfterResponse(object sender, SessionEventArgs e) { // read response headers if (method is not "OPTIONS" && IsProxiedHost(e.HttpClient.Request.RequestUri.Host)) { _logger.LogRequest(new[] { $"{e.HttpClient.Request.Method} {e.HttpClient.Request.Url}" }, MessageType.InterceptedResponse, new LoggingContext(e)); - _pluginEvents.RaiseProxyAfterResponse(new ProxyResponseArgs(e, _throttledRequests, new ResponseState())); + await _pluginEvents.RaiseProxyAfterResponse(new ProxyResponseArgs(e, _throttledRequests, new ResponseState())); } }