Skip to content

Release 3.1.0 - #19

Merged
kampute merged 6 commits into
masterfrom
v3.1.0
Oct 7, 2026
Merged

kampute merged 6 commits into
masterfrom
v3.1.0

Conversation

@kampute

@kampute kampute commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Read problem details, text/xml and suffixed media types

Error bodies in RFC 9457 problem-details format, text/xml, and vendor +json/+xml media types were rejected because each formatter only read its one base media type. With ResponseErrorType set, a problem+json error body was dropped and HttpResponseException.ResponseObject came back null.

Changes

  • JsonFormatter and NewtonsoftJsonFormatter read application/problem+json and advertise it in Accept.
  • XmlFormatter reads text/xml and application/problem+xml and advertises both in Accept.
  • New HttpContentFormatter.CanReadMediaType (protected virtual), which CanRead now calls, and HttpContentFormatter.HasStructuredSyntaxSuffix (protected static).
  • The JSON formatters read any +json media type, and XmlFormatter any +xml media type. These are read but not added to Accept.
  • New MediaTypeNames.Application.ProblemJson and ProblemXml.
  • Upgraded to NUnit 5
  • Version bumped to 3.1.0 for all packages.

The JSON formatters read only application/json and the XML formatter only application/xml. RFC 9457 problem details (application/problem+json and application/problem+xml) returned in error responses could not be read into ResponseErrorType, so HttpResponseException.ResponseObject was null. text/xml, which RFC 7303 registers with the same definition as application/xml, and vendor media types with a +json or +xml structured syntax suffix could not be read either.

JsonFormatter and NewtonsoftJsonFormatter now read application/problem+json, and XmlFormatter reads text/xml and application/problem+xml; these are also advertised in the Accept header. Writing is unchanged.

HttpContentFormatter gains CanReadMediaType, which CanRead calls to decide whether a media type is readable, and HasStructuredSyntaxSuffix. The JSON formatters override CanReadMediaType to read any +json media type and XmlFormatter any +xml media type. These are read but not advertised. The client still reads a response with the first formatter that can read it, so a formatter for a specific suffixed media type must be added before the JSON or XML formatter.

Add MediaTypeNames.Application.ProblemJson and ProblemXml.
Delete the unused "using System.Net.Http;" from Kampute.HttpClient.HttpRequestMessagePropertyKeys.cs to clean up imports and avoid an unnecessary dependency on System.Net.Http (no types from that namespace are referenced).
NUnit 5.0.0 changed Assert.ThrowsAsync, Assert.CatchAsync and Assert.DoesNotThrowAsync to return a Task that must be awaited for the assertion to be evaluated. The test projects no longer compiled: NUnit.Analyzers reported each unawaited call as NUnit2059, and code that read the returned exception failed with CS1061.

Await these assertions and make the enclosing tests async. The .NET Framework test project still uses NUnit 4.6.1 and is unchanged.
Bring the net48 test project to the test package versions of the other test projects: Microsoft.NET.Test.Sdk 18.10.1, NUnit 5.0.0 and NUnit3TestAdapter 6.3.0.

NUnit 5 returns a Task from Assert.ThrowsAsync that must be awaited for the assertion to be evaluated. Await the three calls and make their tests async. The one inside Assert.EnterMultipleScope compiled without an await but would not have checked anything.
@kampute
kampute merged commit b13f2a2 into master Oct 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants