Skip to content

Fixed parsing of incoming comma-separated list of Accept headers #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/JsonApiDotNetCore/Middleware/JsonApiMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

namespace JsonApiDotNetCore.Middleware
Expand Down Expand Up @@ -120,7 +119,7 @@ private static async Task<bool> ValidateContentTypeHeaderAsync(string allowedCon
private static async Task<bool> ValidateAcceptHeaderAsync(MediaTypeHeaderValue allowedMediaTypeValue, HttpContext httpContext,
JsonSerializerSettings serializerSettings)
{
StringValues acceptHeaders = httpContext.Request.Headers["Accept"];
string[] acceptHeaders = httpContext.Request.Headers.GetCommaSeparatedValues("Accept");

if (!acceptHeaders.Any())
{
Expand Down
5 changes: 2 additions & 3 deletions test/TestBuildingBlocks/IntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@ public abstract class IntegrationTest
}
}

using HttpClient client = CreateClient();

if (acceptHeaders != null)
{
foreach (MediaTypeWithQualityHeaderValue acceptHeader in acceptHeaders)
{
client.DefaultRequestHeaders.Accept.Add(acceptHeader);
request.Headers.Accept.Add(acceptHeader);
}
}

using HttpClient client = CreateClient();
HttpResponseMessage responseMessage = await client.SendAsync(request);

string responseText = await responseMessage.Content.ReadAsStringAsync();
Expand Down