@@ -5,6 +5,7 @@ namespace SqlStreamStore.HAL
55 using Microsoft . Owin ;
66 using Microsoft . Owin . Builder ;
77 using Owin ;
8+ using SqlStreamStore . HAL . Resources ;
89 using MidFunc = System . Func < System . Func < System . Collections . Generic . IDictionary < string , object > ,
910 System . Threading . Tasks . Task
1011 > , System . Func < System . Collections . Generic . IDictionary < string , object > ,
@@ -16,12 +17,11 @@ internal static class ReadStreamMiddleware
1617 public static MidFunc UseStreamStore ( IStreamStore streamStore )
1718 {
1819 var streams = new StreamResource ( streamStore ) ;
19-
20+ var streamMessages = new StreamMessageResource ( streamStore ) ;
21+
2022 var builder = new AppBuilder ( )
21- . MapWhen ( IsStreamMessage , inner => inner . Use ( GetStreamMessage ( streams ) ) )
22- . MapWhen ( IsStreamMessageOptions , inner => inner . Use ( GetStreamMessageOptions ) )
23- . MapWhen ( IsStream , inner => inner . Use ( GetStream ( streams ) ) )
24- . MapWhen ( IsStreamOptions , inner => inner . Use ( GetStreamOptions ) ) ;
23+ . MapWhen ( IsStreamMessage , inner => inner . Use ( GetStreamMessage ( streamMessages ) ) )
24+ . MapWhen ( IsStream , inner => inner . Use ( GetStream ( streams ) ) ) ;
2525
2626 return next =>
2727 {
@@ -34,50 +34,30 @@ public static MidFunc UseStreamStore(IStreamStore streamStore)
3434 private static bool IsStream ( IOwinContext context )
3535 => context . IsGetOrHead ( ) && context . Request . Path . IsStream ( ) ;
3636
37- private static bool IsStreamOptions ( IOwinContext context )
38- => context . IsOptions ( ) && context . Request . Path . IsStream ( ) ;
39-
4037 private static bool IsStreamMessage ( IOwinContext context )
4138 => context . IsGetOrHead ( ) && context . Request . Path . IsStreamMessage ( ) ;
4239
43- private static bool IsStreamMessageOptions ( IOwinContext context )
44- => context . IsOptions ( ) && context . Request . Path . IsStreamMessage ( ) ;
45-
46- private static MidFunc GetStream ( StreamResource stream ) => next => async env =>
40+ private static MidFunc GetStream ( StreamResource streams ) => next => async env =>
4741 {
4842 var context = new OwinContext ( env ) ;
4943
5044 var options = new ReadStreamOptions ( context . Request ) ;
5145
52- var response = await stream . GetPage ( options , context . Request . CallCancelled ) ;
46+ var response = await streams . GetPage ( options , context . Request . CallCancelled ) ;
5347
5448 using ( new OptionalHeadRequestWrapper ( context ) )
5549 {
5650 await context . WriteHalResponse ( response ) ;
5751 }
5852 } ;
5953
60- private static MidFunc GetStreamOptions => next => env =>
61- {
62- var context = new OwinContext ( env ) ;
63-
64- context . SetStandardCorsHeaders (
65- HttpMethod . Get ,
66- HttpMethod . Head ,
67- HttpMethod . Options ,
68- HttpMethod . Post ,
69- HttpMethod . Delete ) ;
70-
71- return Task . CompletedTask ;
72- } ;
73-
74- private static MidFunc GetStreamMessage ( StreamResource stream ) => next => async env =>
54+ private static MidFunc GetStreamMessage ( StreamMessageResource streamMessages ) => next => async env =>
7555 {
7656 var context = new OwinContext ( env ) ;
7757
7858 var options = new ReadStreamMessageOptions ( context . Request ) ;
7959
80- var response = await stream . GetMessage ( options , context . Request . CallCancelled ) ;
60+ var response = await streamMessages . GetMessage ( options , context . Request . CallCancelled ) ;
8161
8262 using ( new OptionalHeadRequestWrapper ( context ) )
8363 {
0 commit comments