public async Task InvokeAsync_ConfiguresHeaders()
        {
            // Arrange
            var context = new DefaultHttpContext();

            context.Response.Body = new MemoryStream();
            var middleware = new BrowserScriptMiddleware(_next, BrowserScriptMiddleware.GetWebSocketClientJavaScript("some-host", "test-key"));

            // Act
            await middleware.InvokeAsync(context);

            // Assert
            var response = context.Response;

            Assert.Collection(
                response.Headers.OrderBy(h => h.Key),
                kvp =>
            {
                Assert.Equal("Cache-Control", kvp.Key);
                Assert.Equal("no-store", kvp.Value);
            },
                kvp =>
            {
                Assert.Equal("Content-Length", kvp.Key);
                Assert.NotEmpty(kvp.Value);
            },
                kvp =>
            {
                Assert.Equal("Content-Type", kvp.Key);
                Assert.Equal("application/javascript; charset=utf-8", kvp.Value);
            });
        }
Пример #2
0
        public async Task InvokeAsync_ReturnsScript()
        {
            // Arrange
            var context = new DefaultHttpContext();
            var stream  = new MemoryStream();

            context.Response.Body = stream;
            var middleware = new BrowserScriptMiddleware(_next, BrowserScriptMiddleware.GetWebSocketClientJavaScript("some-host"));

            // Act
            await middleware.InvokeAsync(context);

            // Assert
            stream.Position = 0;
            var script = Encoding.UTF8.GetString(stream.ToArray());

            Assert.Contains("// dotnet-watch browser reload script", script);
            Assert.Contains("'some-host'", script);
        }
Пример #3
0
        public Action <IApplicationBuilder> Configure(Action <IApplicationBuilder> next)
        {
            return(app =>
            {
                app.Map(ApplicationPaths.ClearSiteData, app1 => app1.Run(context =>
                {
                    // Scoped css files can contain links to other css files. We'll try clearing out the http caches to force the browser to re-download.
                    // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data#directives
                    context.Response.Headers["Clear-Site-Data"] = "\"cache\"";
                    return Task.CompletedTask;
                }));

                app.Map(ApplicationPaths.BlazorHotReloadMiddleware, app1 => app1.UseMiddleware <BlazorWasmHotReloadMiddleware>());

                app.Map(ApplicationPaths.BrowserRefreshJS,
                        app1 => app1.UseMiddleware <BrowserScriptMiddleware>(BrowserScriptMiddleware.GetBrowserRefreshJS()));

                app.Map(ApplicationPaths.BlazorHotReloadJS,
                        app1 => app1.UseMiddleware <BrowserScriptMiddleware>(BrowserScriptMiddleware.GetBlazorHotReloadJS()));

                app.UseMiddleware <BrowserRefreshMiddleware>();
                next(app);
            });
        }