public static string GetContentType(Type type, Bug.Common.Enums.FhirFormatType format) { if (typeof(Stu3Model.Resource).IsAssignableFrom(type) || typeof(R4Model.Resource).IsAssignableFrom(type)) { switch (format) { case Bug.Common.Enums.FhirFormatType.json: return(JsonResource); case Bug.Common.Enums.FhirFormatType.xml: return(XmlResource); default: return(XmlResource); } } else { return("application/octet-stream"); } }
public static StringSegment GetMediaTypeHeaderValue(Type type, Bug.Common.Enums.FhirFormatType format) { string mediatype = FhirMediaType.GetContentType(type, format); MediaTypeHeaderValue header = new MediaTypeHeaderValue(mediatype); header.CharSet = Encoding.UTF8.WebName; if (typeof(Stu3Model.Resource).IsAssignableFrom(type)) { return(new StringSegment(header.ToString() + "; FhirVersion=3.0")); } else if (typeof(R4Model.Resource).IsAssignableFrom(type)) { return(new StringSegment(header.ToString() + "; FhirVersion=4.0")); } else { throw new FhirFatalException(System.Net.HttpStatusCode.BadRequest, "Unable to resolve which major version of FHIR is in use."); } }