|
16 | 16 |
|
17 | 17 | public static class SqlStreamStoreHalMiddleware |
18 | 18 | { |
19 | | - private static readonly string[] s_NoCache = |
20 | | - { |
21 | | - "max-age=0", |
22 | | - "no-cache", |
23 | | - "must-revalidate" |
24 | | - }; |
25 | | - |
26 | | - private static readonly string[] s_CacheForOneYear = |
27 | | - { |
28 | | - "max-age=31536000" |
29 | | - }; |
30 | | - |
31 | 19 | private static MidFunc CaseSensitiveQueryStrings => (context, next) => |
32 | 20 | { |
33 | 21 | if(context.Request.QueryString != QueryString.Empty) |
@@ -81,36 +69,43 @@ private static MidFunc MethodsNotAllowed(params string[] methods) => (context, n |
81 | 69 |
|
82 | 70 | public static IApplicationBuilder UseSqlStreamStoreHal( |
83 | 71 | this IApplicationBuilder builder, |
84 | | - IStreamStore streamStore) |
| 72 | + IStreamStore streamStore, |
| 73 | + SqlStreamStoreMiddlewareOptions options = default) |
85 | 74 | { |
86 | 75 | if(builder == null) |
87 | 76 | throw new ArgumentNullException(nameof(builder)); |
88 | 77 | if(streamStore == null) |
89 | 78 | throw new ArgumentNullException(nameof(streamStore)); |
90 | 79 |
|
| 80 | + options = options ?? new SqlStreamStoreMiddlewareOptions(); |
| 81 | + |
91 | 82 | return builder |
92 | 83 | .UseExceptionHandling() |
93 | 84 | .Use(CaseSensitiveQueryStrings) |
94 | 85 | .Use(AcceptHalJson) |
95 | 86 | .Use(HeadRequests) |
96 | 87 | .UseIndex() |
97 | | - .Map("/stream", UseAllStream(streamStore)) |
98 | | - .Map("/streams", UseStream(streamStore)); |
| 88 | + .Map("/stream", UseAllStream(streamStore, options)) |
| 89 | + .Map("/streams", UseStream(streamStore, options)); |
99 | 90 | } |
100 | 91 |
|
101 | | - private static Action<IApplicationBuilder> UseStream(IStreamStore streamStore) |
| 92 | + private static Action<IApplicationBuilder> UseStream( |
| 93 | + IStreamStore streamStore, |
| 94 | + SqlStreamStoreMiddlewareOptions options) |
102 | 95 | => builder => builder |
103 | 96 | .MapWhen(IsOptions, inner => inner.UseStreamOptions(streamStore)) |
104 | 97 | .UseStreamMetadata(streamStore) |
105 | | - .UseReadStream(streamStore) |
| 98 | + .UseReadStream(streamStore, options) |
106 | 99 | .UseAppendStream(streamStore) |
107 | 100 | .UseDeleteStream(streamStore) |
108 | 101 | .Use(MethodsNotAllowed("TRACE", "PATCH")); |
109 | 102 |
|
110 | | - private static Action<IApplicationBuilder> UseAllStream(IStreamStore streamStore) |
| 103 | + private static Action<IApplicationBuilder> UseAllStream( |
| 104 | + IStreamStore streamStore, |
| 105 | + SqlStreamStoreMiddlewareOptions options) |
111 | 106 | => builder => builder |
112 | 107 | .MapWhen(IsOptions, inner => inner.UseAllStreamOptions(streamStore)) |
113 | | - .UseReadAllStream(streamStore) |
| 108 | + .UseReadAllStream(streamStore, options) |
114 | 109 | .Use(MethodsNotAllowed("POST", "PUT", "DELETE", "TRACE", "PATCH")); |
115 | 110 |
|
116 | 111 | private static bool IsOptions(HttpContext context) => context.IsOptions(); |
|
0 commit comments