diff --git a/dev-proxy-plugins/Behavior/RateLimitingPlugin.cs b/dev-proxy-plugins/Behavior/RateLimitingPlugin.cs index 5d3cefd9..dc8a86e5 100644 --- a/dev-proxy-plugins/Behavior/RateLimitingPlugin.cs +++ b/dev-proxy-plugins/Behavior/RateLimitingPlugin.cs @@ -181,18 +181,19 @@ public override void Register(IPluginEvents pluginEvents, } // add rate limiting headers to the response from the API - private async Task OnResponse(object? sender, ProxyResponseArgs e) + private Task OnResponse(object? sender, ProxyResponseArgs e) { if (_urlsToWatch is null || !e.HasRequestUrlMatch(_urlsToWatch)) { - return; + return Task.CompletedTask; } UpdateProxyResponse(e, HttpStatusCode.OK); + return Task.CompletedTask; } - private async Task OnRequest(object? sender, ProxyRequestArgs e) + private Task OnRequest(object? sender, ProxyRequestArgs e) { var session = e.Session; var state = e.ResponseState; @@ -200,7 +201,7 @@ private async Task OnRequest(object? sender, ProxyRequestArgs e) _urlsToWatch is null || !e.ShouldExecute(_urlsToWatch)) { - return; + return Task.CompletedTask; } // set the initial values for the first request @@ -267,5 +268,7 @@ _urlsToWatch is null || } } } + + return Task.CompletedTask; } } diff --git a/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs b/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs index 9733f138..e3dd0f84 100644 --- a/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs +++ b/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs @@ -25,16 +25,17 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.BeforeRequest += OnRequest; } - private async Task OnRequest(object? sender, ProxyRequestArgs e) + private Task OnRequest(object? sender, ProxyRequestArgs e) { if (e.ResponseState.HasBeenSet || _urlsToWatch is null || !e.ShouldExecute(_urlsToWatch)) { - return; + return Task.CompletedTask; } ThrottleIfNecessary(e); + return Task.CompletedTask; } private void ThrottleIfNecessary(ProxyRequestArgs e) diff --git a/dev-proxy-plugins/Guidance/CachingGuidancePlugin.cs b/dev-proxy-plugins/Guidance/CachingGuidancePlugin.cs index 7652cd57..e4e00a25 100644 --- a/dev-proxy-plugins/Guidance/CachingGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/CachingGuidancePlugin.cs @@ -29,11 +29,11 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.BeforeRequest += BeforeRequest; } - private async Task BeforeRequest(object? sender, ProxyRequestArgs e) + private Task BeforeRequest(object? sender, ProxyRequestArgs e) { if (_urlsToWatch is null || !e.HasRequestUrlMatch(_urlsToWatch)) { - return; + return Task.CompletedTask; } Request request = e.Session.HttpClient.Request; @@ -43,7 +43,7 @@ private async Task BeforeRequest(object? sender, ProxyRequestArgs e) if (!_interceptedRequests.ContainsKey(url)) { _interceptedRequests.Add(url, now); - return; + return Task.CompletedTask; } var lastIntercepted = _interceptedRequests[url]; @@ -54,6 +54,7 @@ private async Task BeforeRequest(object? sender, ProxyRequestArgs e) } _interceptedRequests[url] = now; + return Task.CompletedTask; } private static string[] BuildCacheWarningMessage(Request r, int _warningSeconds, DateTime lastIntercepted) => new[] { diff --git a/dev-proxy-plugins/Guidance/GraphBetaSupportGuidancePlugin.cs b/dev-proxy-plugins/Guidance/GraphBetaSupportGuidancePlugin.cs index 0b2ca7ad..8cc69418 100644 --- a/dev-proxy-plugins/Guidance/GraphBetaSupportGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/GraphBetaSupportGuidancePlugin.cs @@ -19,12 +19,14 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.AfterResponse += AfterResponse; } - private async Task AfterResponse(object? sender, ProxyResponseArgs e) { + private Task AfterResponse(object? sender, ProxyResponseArgs e) + { Request request = e.Session.HttpClient.Request; if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && ProxyUtils.IsGraphBetaRequest(request)) _logger?.LogRequest(BuildBetaSupportMessage(request), MessageType.Warning, new LoggingContext(e.Session)); + return Task.CompletedTask; } private static string GetBetaSupportGuidanceUrl() => "https://aka.ms/devproxy/guidance/beta-support"; diff --git a/dev-proxy-plugins/Guidance/GraphClientRequestIdGuidancePlugin.cs b/dev-proxy-plugins/Guidance/GraphClientRequestIdGuidancePlugin.cs index cee87efe..a124c73e 100644 --- a/dev-proxy-plugins/Guidance/GraphClientRequestIdGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/GraphClientRequestIdGuidancePlugin.cs @@ -21,7 +21,7 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.BeforeRequest += BeforeRequest; } - private async Task BeforeRequest(object? sender, ProxyRequestArgs e) + private Task BeforeRequest(object? sender, ProxyRequestArgs e) { Request request = e.Session.HttpClient.Request; if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && WarnNoClientRequestId(request)) @@ -33,6 +33,8 @@ private async Task BeforeRequest(object? sender, ProxyRequestArgs e) _logger?.LogRequest(MessageUtils.BuildUseSdkMessage(request), MessageType.Tip, new LoggingContext(e.Session)); } } + + return Task.CompletedTask; } private static bool WarnNoClientRequestId(Request request) => diff --git a/dev-proxy-plugins/Guidance/GraphSdkGuidancePlugin.cs b/dev-proxy-plugins/Guidance/GraphSdkGuidancePlugin.cs index 87f09f55..86a23b47 100644 --- a/dev-proxy-plugins/Guidance/GraphSdkGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/GraphSdkGuidancePlugin.cs @@ -19,7 +19,8 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.AfterResponse += OnAfterResponse; } - private async Task OnAfterResponse(object? sender, ProxyResponseArgs e) { + private Task OnAfterResponse(object? sender, ProxyResponseArgs e) + { Request request = e.Session.HttpClient.Request; // only show the message if there is an error. if (e.Session.HttpClient.Response.StatusCode >= 400 @@ -28,6 +29,8 @@ private async Task OnAfterResponse(object? sender, ProxyResponseArgs e) { && WarnNoSdk(request)) { _logger?.LogRequest(MessageUtils.BuildUseSdkForErrorsMessage(request), MessageType.Tip, new LoggingContext(e.Session)); } + + return Task.CompletedTask; } private static bool WarnNoSdk(Request request) => ProxyUtils.IsGraphRequest(request) && !ProxyUtils.IsSdkRequest(request); diff --git a/dev-proxy-plugins/Guidance/GraphSelectGuidancePlugin.cs b/dev-proxy-plugins/Guidance/GraphSelectGuidancePlugin.cs index 0ae7525b..1ce46d03 100644 --- a/dev-proxy-plugins/Guidance/GraphSelectGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/GraphSelectGuidancePlugin.cs @@ -21,11 +21,13 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.AfterResponse += AfterResponse; } - private async Task AfterResponse(object? sender, ProxyResponseArgs e) + private Task AfterResponse(object? sender, ProxyResponseArgs e) { Request request = e.Session.HttpClient.Request; if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && WarnNoSelect(request)) _logger?.LogRequest(BuildUseSelectMessage(request), MessageType.Warning, new LoggingContext(e.Session)); + + return Task.CompletedTask; } private bool WarnNoSelect(Request request) diff --git a/dev-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs b/dev-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs index 96633a68..96fd0e94 100644 --- a/dev-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs @@ -21,11 +21,13 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.BeforeRequest += BeforeRequest; } - private async Task BeforeRequest(object sender, ProxyRequestArgs e) + private Task BeforeRequest(object sender, ProxyRequestArgs e) { Request request = e.Session.HttpClient.Request; if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && WarnDeprecatedSearch(request)) _logger?.LogRequest(BuildUseGraphSearchMessage(), MessageType.Warning, new LoggingContext(e.Session)); + + return Task.CompletedTask; } private bool WarnDeprecatedSearch(Request request) diff --git a/dev-proxy-plugins/Guidance/ODataPagingGuidancePlugin.cs b/dev-proxy-plugins/Guidance/ODataPagingGuidancePlugin.cs index 17367624..24b1d928 100644 --- a/dev-proxy-plugins/Guidance/ODataPagingGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/ODataPagingGuidancePlugin.cs @@ -24,13 +24,13 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.BeforeResponse += OnBeforeResponse; } - private async Task OnBeforeRequest(object? sender, ProxyRequestArgs e) + private Task OnBeforeRequest(object? sender, ProxyRequestArgs e) { if (_urlsToWatch is null || e.Session.HttpClient.Request.Method != "GET" || !e.HasRequestUrlMatch(_urlsToWatch)) { - return; + return Task.CompletedTask; } if (IsODataPagingUrl(e.Session.HttpClient.Request.RequestUri) && @@ -38,6 +38,8 @@ private async Task OnBeforeRequest(object? sender, ProxyRequestArgs e) { _logger?.LogRequest(BuildIncorrectPagingUrlMessage(), MessageType.Warning, new LoggingContext(e.Session)); } + + return Task.CompletedTask; } private async Task OnBeforeResponse(object? sender, ProxyResponseArgs e) diff --git a/dev-proxy-plugins/MockResponses/MockResponsePlugin.cs b/dev-proxy-plugins/MockResponses/MockResponsePlugin.cs index 393d89c5..91f66671 100644 --- a/dev-proxy-plugins/MockResponses/MockResponsePlugin.cs +++ b/dev-proxy-plugins/MockResponses/MockResponsePlugin.cs @@ -93,7 +93,8 @@ private void OnOptionsLoaded(object? sender, OptionsLoadedArgs e) { _loader?.InitResponsesWatcher(); } - protected virtual async Task OnRequest(object? sender, ProxyRequestArgs e) { + protected virtual Task OnRequest(object? sender, ProxyRequestArgs e) + { Request request = e.Session.HttpClient.Request; ResponseState state = e.ResponseState; if (!_configuration.NoMocks && _urlsToWatch is not null && e.ShouldExecute(_urlsToWatch)) { @@ -115,6 +116,8 @@ protected virtual async Task OnRequest(object? sender, ProxyRequestArgs e) { state.HasBeenSet = true; } } + + return Task.CompletedTask; } private MockResponse? GetMatchingMockResponse(Request request) { diff --git a/dev-proxy-plugins/RandomErrors/GenericRandomErrorPlugin.cs b/dev-proxy-plugins/RandomErrors/GenericRandomErrorPlugin.cs index 81194db1..585a4787 100644 --- a/dev-proxy-plugins/RandomErrors/GenericRandomErrorPlugin.cs +++ b/dev-proxy-plugins/RandomErrors/GenericRandomErrorPlugin.cs @@ -119,8 +119,8 @@ private void OnInit(object? sender, InitArgs e) { _loader?.InitResponsesWatcher(); } - private async Task OnRequest(object? sender, ProxyRequestArgs e) { - var session = e.Session; + private Task OnRequest(object? sender, ProxyRequestArgs e) + { var state = e.ResponseState; if (!e.ResponseState.HasBeenSet && _urlsToWatch is not null @@ -129,10 +129,12 @@ private async Task OnRequest(object? sender, ProxyRequestArgs e) { if (failMode == GenericRandomErrorFailMode.PassThru && _proxyConfiguration?.Rate != 100) { _logger?.LogRequest(new[] { "Passed through" }, MessageType.PassedThrough, new LoggingContext(e.Session)); - return; + return Task.CompletedTask; } FailResponse(e, failMode); state.HasBeenSet = true; } + + return Task.CompletedTask; } } diff --git a/dev-proxy-plugins/RandomErrors/GraphRandomErrorPlugin.cs b/dev-proxy-plugins/RandomErrors/GraphRandomErrorPlugin.cs index ca2294fa..05495bf5 100644 --- a/dev-proxy-plugins/RandomErrors/GraphRandomErrorPlugin.cs +++ b/dev-proxy-plugins/RandomErrors/GraphRandomErrorPlugin.cs @@ -237,8 +237,8 @@ private void OnOptionsLoaded(object? sender, OptionsLoadedArgs e) { } } - private async Task OnRequest(object? sender, ProxyRequestArgs e) { - var session = e.Session; + private Task OnRequest(object? sender, ProxyRequestArgs e) + { var state = e.ResponseState; if (!e.ResponseState.HasBeenSet && _urlsToWatch is not null @@ -246,7 +246,7 @@ private async Task OnRequest(object? sender, ProxyRequestArgs e) { var failMode = ShouldFail(e); if (failMode == GraphRandomErrorFailMode.PassThru && _proxyConfiguration?.Rate != 100) { - return; + return Task.CompletedTask; } if (ProxyUtils.IsGraphBatchUrl(e.Session.HttpClient.Request.RequestUri)) { FailBatch(e); @@ -256,5 +256,7 @@ private async Task OnRequest(object? sender, ProxyRequestArgs e) { } state.HasBeenSet = true; } + + return Task.CompletedTask; } } diff --git a/dev-proxy-plugins/RequestLogs/ExecutionSummaryPlugin.cs b/dev-proxy-plugins/RequestLogs/ExecutionSummaryPlugin.cs index b9172824..3c8fc7e1 100644 --- a/dev-proxy-plugins/RequestLogs/ExecutionSummaryPlugin.cs +++ b/dev-proxy-plugins/RequestLogs/ExecutionSummaryPlugin.cs @@ -106,11 +106,11 @@ private void OnOptionsLoaded(object? sender, OptionsLoadedArgs e) } } - private async Task AfterRecordingStop(object? sender, RecordingArgs e) + private Task AfterRecordingStop(object? sender, RecordingArgs e) { if (!e.RequestLogs.Any()) { - return; + return Task.CompletedTask; } var report = _configuration.GroupBy switch @@ -128,6 +128,8 @@ private async Task AfterRecordingStop(object? sender, RecordingArgs e) { File.WriteAllLines(_configuration.FilePath, report); } + + return Task.CompletedTask; } private string[] GetGroupedByUrlReport(IEnumerable requestLogs) diff --git a/dev-proxy-plugins/RequestLogs/MockGeneratorPlugin.cs b/dev-proxy-plugins/RequestLogs/MockGeneratorPlugin.cs index 94ff5f1c..88a5c871 100644 --- a/dev-proxy-plugins/RequestLogs/MockGeneratorPlugin.cs +++ b/dev-proxy-plugins/RequestLogs/MockGeneratorPlugin.cs @@ -23,14 +23,14 @@ public override void Register(IPluginEvents pluginEvents, pluginEvents.AfterRecordingStop += AfterRecordingStop; } - private async Task AfterRecordingStop(object? sender, RecordingArgs e) + private Task AfterRecordingStop(object? sender, RecordingArgs e) { _logger?.LogInfo("Creating mocks from recorded requests..."); if (!e.RequestLogs.Any()) { _logger?.LogDebug("No requests to process"); - return; + return Task.CompletedTask; } var methodAndUrlComparer = new MethodAndUrlComparer(); @@ -86,6 +86,8 @@ request.Context is null || File.WriteAllText(fileName, mocksFileJson); _logger?.LogInfo($"Created mock file {fileName} with {mocks.Count} mocks"); + + return Task.CompletedTask; } ///