brianpos / fhir-net-web-api

.NET FHIR webapi and netapicore facade library
Other
27 stars 13 forks source link

Ignore Header parameters so that charset=utf-8 will not fail to match on a valid Formatter #17

Open JoeShook opened 9 months ago

JoeShook commented 9 months ago

The existing behavior can be seen by running the Hl7.DemoFileSystemFhirServer.AspNetCore project as is. Requesting a fhir resource with an "Accept" header of "application/json+fhir; charset=utf-8" I would expect the results to be json but they are returned as xml. But, because the base type of TextInputFormatter matches on the header parameters also we do not find a matching formatter and return the first one registered.

This PR overrides CanWriteResult to ignore the header parameter. This results in the Json Formatter being selected for output formatting. It may be appropriate to check encoding if it exists and ensure it is not something other than utf-8. Also this code would allow a path forward for other misc header parameters like fhirVersion.