Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 87f64b9

Browse files
moving this ot of middleware and back to the resource
1 parent d3f2809 commit 87f64b9

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/SqlStreamStore.HAL/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class Headers
99
{
1010
public const string ExpectedVersion = "SSS-ExpectedVersion";
1111
public const string HeadPosition = "SSS-HeadPosition";
12+
public const string Location = "Location";
1213

1314
public static class ContentTypes
1415
{

src/SqlStreamStore.HAL/ReadStreamMiddleware.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ namespace SqlStreamStore.HAL
33
using Microsoft.Owin;
44
using Microsoft.Owin.Builder;
55
using Owin;
6-
using SqlStreamStore.Streams;
76
using MidFunc = System.Func<System.Func<System.Collections.Generic.IDictionary<string, object>,
87
System.Threading.Tasks.Task
98
>, System.Func<System.Collections.Generic.IDictionary<string, object>,
@@ -56,14 +55,6 @@ private static MidFunc GetStreamMessage(StreamResource stream) => next => async
5655

5756
var response = await stream.GetMessage(options, context.Request.CallCancelled);
5857

59-
if(options.StreamVersion == StreamVersion.End)
60-
{
61-
context.Response.StatusCode = 307;
62-
context.Response.Headers["Location"] = $"{((dynamic) response.Hal.Model).StreamVersion}";
63-
64-
return;
65-
}
66-
6758
using(new OptionalHeadRequestWrapper(context))
6859
{
6960
await context.WriteHalResponse(response);

src/SqlStreamStore.HAL/StreamResource.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task<Response> AppendMessages(
3434
: 200);
3535
if(options.ExpectedVersion == ExpectedVersion.NoStream)
3636
{
37-
response.Headers["Location"] = new[] { $"streams/{options.StreamId}" };
37+
response.Headers[Constants.Headers.Location] = new[] { $"streams/{options.StreamId}" };
3838
}
3939
return response;
4040
}
@@ -60,6 +60,18 @@ public async Task<Response> GetMessage(
6060
.AddLinks(StreamLinks.Feed(options)),
6161
404);
6262
}
63+
64+
if(options.StreamVersion == StreamVersion.End)
65+
{
66+
return new Response(new HALResponse(new object()), 307)
67+
{
68+
Headers =
69+
{
70+
[Constants.Headers.Location] = new[] { $"{message.StreamVersion}" }
71+
}
72+
};
73+
}
74+
6375

6476
var payload = await message.GetJsonData(cancellationToken);
6577

0 commit comments

Comments
 (0)