diff --git a/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs b/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs index e3dd0f84..c641202e 100644 --- a/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs +++ b/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs @@ -29,6 +29,7 @@ private Task OnRequest(object? sender, ProxyRequestArgs e) { if (e.ResponseState.HasBeenSet || _urlsToWatch is null || + e.Session.HttpClient.Request.Method.ToUpper() == "OPTIONS" || !e.ShouldExecute(_urlsToWatch)) { return Task.CompletedTask; diff --git a/dev-proxy-plugins/Guidance/CachingGuidancePlugin.cs b/dev-proxy-plugins/Guidance/CachingGuidancePlugin.cs index e4e00a25..1924d434 100644 --- a/dev-proxy-plugins/Guidance/CachingGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/CachingGuidancePlugin.cs @@ -31,7 +31,9 @@ public override void Register(IPluginEvents pluginEvents, private Task BeforeRequest(object? sender, ProxyRequestArgs e) { - if (_urlsToWatch is null || !e.HasRequestUrlMatch(_urlsToWatch)) + if (_urlsToWatch is null || + !e.HasRequestUrlMatch(_urlsToWatch) || + e.Session.HttpClient.Request.Method.ToUpper() == "OPTIONS") { return Task.CompletedTask; } diff --git a/dev-proxy-plugins/Guidance/GraphBetaSupportGuidancePlugin.cs b/dev-proxy-plugins/Guidance/GraphBetaSupportGuidancePlugin.cs index 8cc69418..10340ed5 100644 --- a/dev-proxy-plugins/Guidance/GraphBetaSupportGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/GraphBetaSupportGuidancePlugin.cs @@ -24,6 +24,7 @@ private Task AfterResponse(object? sender, ProxyResponseArgs e) Request request = e.Session.HttpClient.Request; if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && + e.Session.HttpClient.Request.Method.ToUpper() != "OPTIONS" && ProxyUtils.IsGraphBetaRequest(request)) _logger?.LogRequest(BuildBetaSupportMessage(request), MessageType.Warning, new LoggingContext(e.Session)); return Task.CompletedTask; diff --git a/dev-proxy-plugins/Guidance/GraphClientRequestIdGuidancePlugin.cs b/dev-proxy-plugins/Guidance/GraphClientRequestIdGuidancePlugin.cs index a124c73e..20bc99bd 100644 --- a/dev-proxy-plugins/Guidance/GraphClientRequestIdGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/GraphClientRequestIdGuidancePlugin.cs @@ -24,7 +24,10 @@ public override void Register(IPluginEvents pluginEvents, private Task BeforeRequest(object? sender, ProxyRequestArgs e) { Request request = e.Session.HttpClient.Request; - if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && WarnNoClientRequestId(request)) + if (_urlsToWatch is not null && + e.HasRequestUrlMatch(_urlsToWatch) && + e.Session.HttpClient.Request.Method.ToUpper() != "OPTIONS" && + WarnNoClientRequestId(request)) { _logger?.LogRequest(BuildAddClientRequestIdMessage(request), MessageType.Warning, new LoggingContext(e.Session)); diff --git a/dev-proxy-plugins/Guidance/GraphSdkGuidancePlugin.cs b/dev-proxy-plugins/Guidance/GraphSdkGuidancePlugin.cs index 86a23b47..989c51b1 100644 --- a/dev-proxy-plugins/Guidance/GraphSdkGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/GraphSdkGuidancePlugin.cs @@ -23,10 +23,11 @@ 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 - && _urlsToWatch is not null - && e.HasRequestUrlMatch(_urlsToWatch) - && WarnNoSdk(request)) { + if (e.Session.HttpClient.Response.StatusCode >= 400 && + _urlsToWatch is not null && + e.HasRequestUrlMatch(_urlsToWatch) && + e.Session.HttpClient.Request.Method.ToUpper() != "OPTIONS" && + WarnNoSdk(request)) { _logger?.LogRequest(MessageUtils.BuildUseSdkForErrorsMessage(request), MessageType.Tip, new LoggingContext(e.Session)); } diff --git a/dev-proxy-plugins/Guidance/GraphSelectGuidancePlugin.cs b/dev-proxy-plugins/Guidance/GraphSelectGuidancePlugin.cs index 1ce46d03..0dbe2b3a 100644 --- a/dev-proxy-plugins/Guidance/GraphSelectGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/GraphSelectGuidancePlugin.cs @@ -24,7 +24,10 @@ public override void Register(IPluginEvents pluginEvents, private Task AfterResponse(object? sender, ProxyResponseArgs e) { Request request = e.Session.HttpClient.Request; - if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && WarnNoSelect(request)) + if (_urlsToWatch is not null && + e.HasRequestUrlMatch(_urlsToWatch) && + e.Session.HttpClient.Request.Method.ToUpper() != "OPTIONS" && + WarnNoSelect(request)) _logger?.LogRequest(BuildUseSelectMessage(request), MessageType.Warning, new LoggingContext(e.Session)); return Task.CompletedTask; diff --git a/dev-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs b/dev-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs index 96fd0e94..8387b10c 100644 --- a/dev-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs +++ b/dev-proxy-plugins/Guidance/ODSPSearchGuidancePlugin.cs @@ -24,7 +24,10 @@ public override void Register(IPluginEvents pluginEvents, private Task BeforeRequest(object sender, ProxyRequestArgs e) { Request request = e.Session.HttpClient.Request; - if (_urlsToWatch is not null && e.HasRequestUrlMatch(_urlsToWatch) && WarnDeprecatedSearch(request)) + if (_urlsToWatch is not null && + e.HasRequestUrlMatch(_urlsToWatch) && + e.Session.HttpClient.Request.Method.ToUpper() != "OPTIONS" && + WarnDeprecatedSearch(request)) _logger?.LogRequest(BuildUseGraphSearchMessage(), MessageType.Warning, new LoggingContext(e.Session)); return Task.CompletedTask; diff --git a/dev-proxy/ProxyEngine.cs b/dev-proxy/ProxyEngine.cs index 3d17f53b..dd619cb1 100644 --- a/dev-proxy/ProxyEngine.cs +++ b/dev-proxy/ProxyEngine.cs @@ -352,9 +352,7 @@ private bool IsProxiedProcess(TunnelConnectSessionEventArgs e) { } async Task OnRequest(object sender, SessionEventArgs e) { - var method = e.HttpClient.Request.Method.ToUpper(); - // The proxy does not intercept or alter OPTIONS requests - if (method is not "OPTIONS" && IsProxiedHost(e.HttpClient.Request.RequestUri.Host)) { + if (IsProxiedHost(e.HttpClient.Request.RequestUri.Host)) { // we need to keep the request body for further processing // by plugins e.HttpClient.Request.KeepBody = true; @@ -386,20 +384,20 @@ private async Task HandleRequest(SessionEventArgs e) { // Modify response async Task OnBeforeResponse(object sender, SessionEventArgs e) { - var method = e.HttpClient.Request.Method.ToUpper(); // read response headers - if (method is not "OPTIONS" && IsProxiedHost(e.HttpClient.Request.RequestUri.Host)) { + if (IsProxiedHost(e.HttpClient.Request.RequestUri.Host)) { // necessary to make the response body available to plugins e.HttpClient.Response.KeepBody = true; - await e.GetResponseBody(); + if (e.HttpClient.Response.HasBody) { + await e.GetResponseBody(); + } await _pluginEvents.RaiseProxyBeforeResponse(new ProxyResponseArgs(e, _throttledRequests, new ResponseState())); } } async Task OnAfterResponse(object sender, SessionEventArgs e) { - var method = e.HttpClient.Request.Method.ToUpper(); // read response headers - if (method is not "OPTIONS" && IsProxiedHost(e.HttpClient.Request.RequestUri.Host)) { + if (IsProxiedHost(e.HttpClient.Request.RequestUri.Host)) { _logger.LogRequest(new[] { $"{e.HttpClient.Request.Method} {e.HttpClient.Request.Url}" }, MessageType.InterceptedResponse, new LoggingContext(e)); await _pluginEvents.RaiseProxyAfterResponse(new ProxyResponseArgs(e, _throttledRequests, new ResponseState())); }