@@ -33,8 +33,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services) => servic
3333
3434 public void Configure ( IApplicationBuilder app ) => app
3535 . UseResponseCompression ( )
36+ . Use ( VaryAccept )
3637 . Use ( CatchAndDisplayErrors )
37- . Use ( AllowAllOrigins )
3838 . Use ( SqlStreamStreamBrowserJavascript )
3939 . Use ( SqlStreamStreamBrowserHtml )
4040 . UseSqlStreamStoreHal ( _streamStore ) ;
@@ -51,28 +51,22 @@ public void Configure(IApplicationBuilder app) => app
5151 }
5252 } ;
5353
54- // don't actually do this in production
55- private static MidFunc AllowAllOrigins => ( context , next ) =>
54+ private static MidFunc VaryAccept => ( context , next ) =>
5655 {
57- context . Response . OnStarting ( _ =>
58- {
59- var response = ( HttpResponse ) _ ;
60- response . Headers [ "Access-Control-Allow-Origin" ] = "*" ;
56+ Task Vary ( object state )
57+ {
58+ var response = ( HttpResponse ) state ;
6159
62- return Task . CompletedTask ;
63- } ,
64- context . Response ) ;
60+ response . Headers . AppendCommaSeparatedValues ( "Vary" , "Accept" ) ;
6561
62+ return Task . CompletedTask ;
63+ }
64+
65+ context . Response . OnStarting ( Vary , context . Response ) ;
66+
6667 return next ( ) ;
6768 } ;
6869
69- private static string [ ] GetAcceptHeaders ( HttpRequest contextRequest )
70- => Array . ConvertAll (
71- contextRequest . Headers . GetCommaSeparatedValues ( "Accept" ) ,
72- value => MediaTypeWithQualityHeaderValue . TryParse ( value , out var header )
73- ? header . MediaType
74- : null ) ;
75-
7670 private MidFunc SqlStreamStreamBrowserJavascript => ( context , next ) =>
7771 {
7872 if ( context . Request . Path . Value ? . EndsWith ( ".js" ) ?? false )
@@ -96,6 +90,13 @@ private static string[] GetAcceptHeaders(HttpRequest contextRequest)
9690 ? ForwardToClientDevServer ( context , context . Request . PathBase . ToUriComponent ( ) )
9791 : next ( ) ;
9892
93+ private static string [ ] GetAcceptHeaders ( HttpRequest contextRequest )
94+ => Array . ConvertAll (
95+ contextRequest . Headers . GetCommaSeparatedValues ( "Accept" ) ,
96+ value => MediaTypeWithQualityHeaderValue . TryParse ( value , out var header )
97+ ? header . MediaType
98+ : null ) ;
99+
99100 private Task RedirectToPathBase ( HttpContext context , PathString path )
100101 {
101102 context . Response . Redirect ( context . Request . PathBase + path ) ;
0 commit comments