Skip to content

Commit a103cb9

Browse files
Handle parameters in Accepts mediatypes in DefaultProblemDetailsWriter (#54158)
Co-authored-by: Safia Abdalla <[email protected]>
1 parent 197acb1 commit a103cb9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Http/Http.Extensions/src/DefaultProblemDetailsWriter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public bool CanWrite(ProblemDetailsContext context)
3434
{
3535
return true;
3636
}
37-
3837
for (var i = 0; i < acceptHeader.Count; i++)
3938
{
4039
var acceptHeaderValue = acceptHeader[i];
41-
42-
if (_jsonMediaType.IsSubsetOf(acceptHeaderValue) ||
43-
_problemDetailsJsonMediaType.IsSubsetOf(acceptHeaderValue))
40+
// Check to see if the Accepted header values support `application/json` or `application/problem+json`
41+
// with support for argument parameters. Support handling `*/*` and `application/*` as Accepts header values.
42+
// Application/json is a subset of */* but */* is not a subset of application/json
43+
if (acceptHeaderValue.IsSubsetOf(_jsonMediaType) || acceptHeaderValue.IsSubsetOf(_problemDetailsJsonMediaType) || _jsonMediaType.IsSubsetOf(acceptHeaderValue))
4444
{
4545
return true;
4646
}

src/Http/Http.Extensions/test/ProblemDetailsDefaultWriterTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ await writer.WriteAsync(new ProblemDetailsContext()
600600
[InlineData("application/*")]
601601
[InlineData("application/json")]
602602
[InlineData("application/problem+json")]
603+
[InlineData("application/json; charset=utf-8")]
604+
[InlineData("application/json; v=1.0")]
603605
public void CanWrite_ReturnsTrue_WhenJsonAccepted(string contentType)
604606
{
605607
// Arrange

0 commit comments

Comments
 (0)