Skip to content

Commit

Permalink
Excludes OPTIONS requests from ApiCenterProductionVersionPlugin (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
waldekmastykarz committed May 17, 2024
1 parent de9521b commit 9ab4177
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions dev-proxy-plugins/RequestLogs/ApiCenterProductionVersionPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,21 @@ private async Task AfterRecordingStop(object sender, RecordingArgs e)

foreach (var request in interceptedRequests)
{
var urlAndMethodString = request.MessageLines.First();
var urlAndMethod = urlAndMethodString.Split(' ');
var methodAndUrlString = request.MessageLines.First();
var methodAndUrl = methodAndUrlString.Split(' ');
if (methodAndUrl[0] == "OPTIONS")
{
_logger?.LogDebug("Skipping OPTIONS request {request}", methodAndUrl[1]);
continue;
}

var apiInformation = FindMatchingApiInformation(urlAndMethod[1], apisInformation);
var apiInformation = FindMatchingApiInformation(methodAndUrl[1], apisInformation);
if (apiInformation == null)
{
continue;
}

var lifecycleStage = FindMatchingApiLifecycleStage(request, urlAndMethod[1], apiInformation);
var lifecycleStage = FindMatchingApiLifecycleStage(request, methodAndUrl[1], apiInformation);
if (lifecycleStage == null)
{
continue;
Expand All @@ -252,11 +257,11 @@ private async Task AfterRecordingStop(object sender, RecordingArgs e)

if (productionVersions.Any())
{
_logger?.LogWarning("Request {request} uses API version {version} which is defined as {lifecycleStage}. Upgrade to a production version of the API. Recommended versions: {versions}", urlAndMethodString, apiInformation.Versions.First(v => v.LifecycleStage == lifecycleStage).Title, lifecycleStage, string.Join(", ", productionVersions));
_logger?.LogWarning("Request {request} uses API version {version} which is defined as {lifecycleStage}. Upgrade to a production version of the API. Recommended versions: {versions}", methodAndUrlString, apiInformation.Versions.First(v => v.LifecycleStage == lifecycleStage).Title, lifecycleStage, string.Join(", ", productionVersions));
}
else
{
_logger?.LogWarning("Request {request} uses API version {version} which is defined as {lifecycleStage}.", urlAndMethodString, apiInformation.Versions.First(v => v.LifecycleStage == lifecycleStage).Title, lifecycleStage);
_logger?.LogWarning("Request {request} uses API version {version} which is defined as {lifecycleStage}.", methodAndUrlString, apiInformation.Versions.First(v => v.LifecycleStage == lifecycleStage).Title, lifecycleStage);
}
}
}
Expand Down

0 comments on commit 9ab4177

Please sign in to comment.