Skip to content

Commit 6289373

Browse files
author
Bart Koelman
authored
Fixed parsing of incoming comma-separated list of Accept headers (#973)
1 parent 59d2b51 commit 6289373

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/JsonApiDotNetCore/Middleware/JsonApiMiddleware.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Microsoft.AspNetCore.Mvc;
1717
using Microsoft.AspNetCore.Mvc.Controllers;
1818
using Microsoft.AspNetCore.Routing;
19-
using Microsoft.Extensions.Primitives;
2019
using Newtonsoft.Json;
2120

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

125124
if (!acceptHeaders.Any())
126125
{

test/TestBuildingBlocks/IntegrationTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,15 @@ public abstract class IntegrationTest
6363
}
6464
}
6565

66-
using HttpClient client = CreateClient();
67-
6866
if (acceptHeaders != null)
6967
{
7068
foreach (MediaTypeWithQualityHeaderValue acceptHeader in acceptHeaders)
7169
{
72-
client.DefaultRequestHeaders.Accept.Add(acceptHeader);
70+
request.Headers.Accept.Add(acceptHeader);
7371
}
7472
}
7573

74+
using HttpClient client = CreateClient();
7675
HttpResponseMessage responseMessage = await client.SendAsync(request);
7776

7877
string responseText = await responseMessage.Content.ReadAsStringAsync();

0 commit comments

Comments
 (0)