@@ -22,7 +22,7 @@ public static class SqlStreamStoreHalMiddleware
2222
2323 context . Response . OnSendingHeaders ( _ =>
2424 {
25- context . Response . Headers [ "Access-Control-Allow-Methods" ] = "GET, HEAD, OPTIONS" ;
25+ context . Response . Headers [ "Access-Control-Allow-Methods" ] = "GET, HEAD, OPTIONS, POST, DELETE " ;
2626 context . Response . Headers [ "Access-Control-Allow-Headers" ]
2727 = "Content-Type, X-Requested-With, Authorization" ;
2828 context . Response . Headers [ "Access-Control-Allow-Origin" ] = "*" ;
@@ -50,6 +50,19 @@ public static class SqlStreamStoreHalMiddleware
5050 return next ( env ) ;
5151 } ;
5252
53+ private static MidFunc MethodsNotAllowed ( params string [ ] methods ) => next => env =>
54+ {
55+ var context = new OwinContext ( env ) ;
56+
57+ if ( ! methods . Contains ( context . Request . Method ) )
58+ {
59+ return next ( env ) ;
60+ }
61+
62+ context . Response . StatusCode = 405 ;
63+
64+ return Task . CompletedTask ;
65+ } ;
5366
5467 private static MidFunc AcceptOnlyHalJson => next => env =>
5568 {
@@ -100,12 +113,12 @@ public static MidFunc UseSqlStreamStoreHal(IStreamStore streamStore)
100113 . Use ( Index )
101114 . Map ( "/stream" , inner => inner
102115 . Use ( ReadAllStreamMiddleware . UseStreamStore ( streamStore ) )
103- . Use ( MethodsNotAllowed ( "POST" , "PUT" , "DELETE" , "TRACE" , "PATCH" , "OPTIONS" ) ) )
116+ . Use ( MethodsNotAllowed ( "POST" , "PUT" , "DELETE" , "TRACE" , "PATCH" ) ) )
104117 . Map ( "/streams" , inner => inner
105118 . Use ( ReadStreamMiddleware . UseStreamStore ( streamStore ) )
106119 . Use ( AppendStreamMiddleware . UseStreamStore ( streamStore ) )
107120 . Use ( DeleteStreamMiddleware . UseStreamStore ( streamStore ) )
108- . Use ( MethodsNotAllowed ( "DELETE" , " TRACE", "PATCH" , "OPTIONS ") ) ) ;
121+ . Use ( MethodsNotAllowed ( "TRACE" , "PATCH" ) ) ) ;
109122
110123 return next =>
111124 {
@@ -115,19 +128,5 @@ public static MidFunc UseSqlStreamStoreHal(IStreamStore streamStore)
115128 } ;
116129 }
117130
118- private static MidFunc MethodsNotAllowed ( params string [ ] methods )
119- => next => env =>
120- {
121- var context = new OwinContext ( env ) ;
122-
123- if ( ! methods . Contains ( context . Request . Method ) )
124- {
125- return next ( env ) ;
126- }
127-
128- context . Response . StatusCode = 405 ;
129-
130- return Task . CompletedTask ;
131- } ;
132131 }
133132}
0 commit comments