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

Commit d3f2809

Browse files
cleaning up allowed methods
1 parent af4d4a6 commit d3f2809

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

src/SqlStreamStore.HAL/SqlStreamStoreHalMiddleware.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)