Skip to content

Commit

Permalink
Remove call to .Any() from ProblemDetailsDefaultWriter (#43055)
Browse files Browse the repository at this point in the history
* Remove call to .Any()

* Removing System.Linq
  • Loading branch information
brunolins16 committed Aug 3, 2022
1 parent 2d5f11b commit 846f0fd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Http/Http.Extensions/src/DefaultProblemDetailsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
Expand All @@ -26,9 +25,18 @@ public bool CanWrite(ProblemDetailsContext context)
var httpContext = context.HttpContext;
var acceptHeader = httpContext.Request.Headers.Accept.GetList<MediaTypeHeaderValue>();

if (acceptHeader?.Any(h => _jsonMediaType.IsSubsetOf(h) || _problemDetailsJsonMediaType.IsSubsetOf(h)) == true)
if (acceptHeader is { Count: > 0 })
{
return true;
for (var i = 0; i < acceptHeader.Count; i++)
{
var acceptHeaderValue = acceptHeader[i];

if (_jsonMediaType.IsSubsetOf(acceptHeaderValue) ||
_problemDetailsJsonMediaType.IsSubsetOf(acceptHeaderValue))
{
return true;
}
}
}

return false;
Expand Down

0 comments on commit 846f0fd

Please sign in to comment.