Example #1
0
        public override void WriteResponseHeaders(OutputFormatterWriteContext context)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.ContentType = FhirMediaType.GetMediaTypeHeaderValue(context.ObjectType, Bug.Common.Enums.FhirFormatType.json);
            // note that the base is called last, as this may overwrite the ContentType where the resource is of type Binary
            base.WriteResponseHeaders(context);
            //   headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "fhir.resource.json" };
        }
Example #2
0
        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.");
            }
        }