Skip to content

Commit

Permalink
Merge branch 'develop' into stu3/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethmyhra committed Mar 8, 2020
2 parents 599f834 + b893f3a commit 413bc8e
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 7 deletions.
23 changes: 22 additions & 1 deletion src/Spark.Engine/Extensions/HttpRequestFhirExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ internal static bool IsRawBinaryPostOrPutRequest(this HttpRequest request)
&& !HttpRequestExtensions.IsContentTypeHeaderFhirMediaType(request.ContentType)
&& (request.Method == "POST" || request.Method == "PUT");
}

internal static void AcquireHeaders(this HttpResponse response, FhirResponse fhirResponse)
{
if (fhirResponse.Key != null)
{
response.Headers.Add("ETag", ETag.Create(fhirResponse.Key.VersionId)?.ToString());

Uri location = fhirResponse.Key.ToUri();
response.Headers.Add("Location", location.OriginalString);

if (response.Body != null)
{
response.Headers.Add("Content-Location", location.OriginalString);
if (fhirResponse.Resource != null && fhirResponse.Resource.Meta != null)
{
response.Headers.Add("Last-Modified", fhirResponse.Resource.Meta.LastUpdated.Value.ToString("R"));
}
}
}
}

#endif

internal static void AcquireHeaders(this HttpResponseMessage response, FhirResponse fhirResponse)
Expand All @@ -166,7 +187,7 @@ internal static void AcquireHeaders(this HttpResponseMessage response, FhirRespo
}
}
}

private static HttpResponseMessage CreateBareFhirResponse(this HttpRequestMessage request, FhirResponse fhir)
{
bool includebody = request.PreferRepresentation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public static IMvcCoreBuilder AddFhir(this IServiceCollection services, SparkSet
services.RemoveAll<OutputFormatterSelector>();
services.TryAddSingleton<OutputFormatterSelector, FhirOutputFormatterSelector>();

services.RemoveAll<OutputFormatterSelector>();
services.TryAddSingleton<OutputFormatterSelector, FhirOutputFormatterSelector>();

return builder;
}

Expand Down
8 changes: 7 additions & 1 deletion src/Spark.Engine/Formatters/NetCore/BinaryOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FhirModel = Hl7.Fhir.Model;
using Microsoft.AspNetCore.Mvc.Formatters;
using Spark.Engine.Core;
using Spark.Engine.Extensions;
using System;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -28,12 +29,17 @@ public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext co
if (typeof(FhirResponse).IsAssignableFrom(context.ObjectType))
{
FhirResponse response = (FhirResponse)context.Object;

context.HttpContext.Response.AcquireHeaders(response);
context.HttpContext.Response.StatusCode = (int)response.StatusCode;

binary = response.Resource as FhirModel.Binary;
}
if (binary == null) return;

Stream stream = new MemoryStream(binary.Content);
context.HttpContext.Response.ContentType = binary.ContentType;

Stream stream = new MemoryStream(binary.Content);
await stream.CopyToAsync(context.HttpContext.Response.Body);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context,
if (typeof(FhirResponse).IsAssignableFrom(context.ObjectType))
{
FhirResponse response = context.Object as FhirResponse;

context.HttpContext.Response.AcquireHeaders(response);
context.HttpContext.Response.StatusCode = (int)response.StatusCode;

if (response.Resource != null)
serializer.Serialize(response.Resource, jsonWriter, summaryType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public override Task WriteResponseBodyAsync(OutputFormatterWriteContext context,
if (typeof(FhirResponse).IsAssignableFrom(context.ObjectType))
{
FhirResponse response = context.Object as FhirResponse;

context.HttpContext.Response.AcquireHeaders(response);
context.HttpContext.Response.StatusCode = (int)response.StatusCode;

if (response.Resource != null)
serializer.Serialize(response.Resource, xmlWriter, summaryType);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Spark.Engine/Spark.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<PackageId>Spark.Engine.STU3</PackageId>
<Version>1.3.0</Version>
<Version>1.4.0-beta01</Version>
<Copyright>Copyright © Firely 2014, © Kufu 2018</Copyright>
<Company>Firely and Kufu</Company>
<Authors>Firely, Kufu and contributors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/Spark.Mongo/Spark.Mongo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Spark.Mongo.STU3</PackageId>
<Version>1.3.0</Version>
<Version>1.4.0-beta01</Version>
<Copyright>Copyright © Firely 2014, © Kufu 2018</Copyright>
<Company>Firely and Kufu</Company>
<Authors>Firely, Kufu and contributors</Authors>
Expand Down
9 changes: 9 additions & 0 deletions src/Spark.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Spark.Web.Services;
using Spark.Web.Hubs;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.ResponseCompression;
using System.Linq;

namespace Spark.Web
{
Expand Down Expand Up @@ -55,6 +57,13 @@ public void ConfigureServices(IServiceCollection services)
options.MinimumSameSitePolicy = SameSiteMode.None;
});

services.AddResponseCompression(options =>
{
options.Providers.Add<GzipCompressionProvider>();
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/fhir+json", "application/fhir+xml" });
});

// Add database context for user administration
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))
Expand Down
2 changes: 1 addition & 1 deletion src/Spark.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"DefaultConnection": "Data Source=database.db"
},
"StoreSettings": {
"ConnectionString": "mongodb://root:CosmicTopSecret@localhost:27017/spark?authSource=admin"
"ConnectionString": "mongodb://localhost:27017/spark"
},
"SparkSettings": {
"Endpoint": "https://localhost:5001/fhir"
Expand Down
2 changes: 1 addition & 1 deletion src/Spark/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("14.8.0.0")]
[assembly: AssemblyVersion("14.9.0.0")]

2 changes: 1 addition & 1 deletion src/Spark/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<add key="FHIR_ENDPOINT" value="http://localhost:49911/fhir" />
<add key="MaxBinarySize" value="65536" />
<add key="MaxDecompressedBodySizeInBytes" value="20971520" />
<add key="FhirRelease" value="STU3" />
<add key="FhirRelease" value="STU3" />
<add key="PermissiveParsing" value="true" />
</appSettings>
<!--
Expand Down

0 comments on commit 413bc8e

Please sign in to comment.