Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.AspNetCore.Components.Endpoints.Rendering;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -116,6 +117,16 @@ await EndpointHtmlRenderer.InitializeStandardComponentServicesAsync(
}
}

if (!quiesceTask.IsCompleted)
{
// An incomplete QuiescenceTask indicates there may be streaming rendering updates.
// Disable all response buffering and compression on IIS like SignalR's ServerSentEventsServerTransport does.
var bufferingFeature = context.Features.GetRequiredFeature<IHttpResponseBodyFeature>();
bufferingFeature.DisableBuffering();

context.Response.Headers.ContentEncoding = "identity";
}

// Importantly, we must not yield this thread (which holds exclusive access to the renderer sync context)
// in between the first call to htmlContent.WriteTo and the point where we start listening for subsequent
// streaming SSR batches (inside SendStreamingUpdatesAsync). Otherwise some other code might dispatch to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

using System.Globalization;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.RegularExpressions;
using Components.TestServer.RazorComponents;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
using Microsoft.AspNetCore.E2ETesting;
using Microsoft.Net.Http.Headers;
using OpenQA.Selenium;
using TestServer;
using Xunit.Abstractions;
Expand All @@ -30,13 +30,29 @@ public override Task InitializeAsync()
=> InitializeAsync(BrowserFixture.StreamingContext);

[Fact]
public void CanRenderNonstreamingPageWithoutInjectingStreamingMarkers()
public async Task CanRenderNonstreamingPageWithoutInjectingStreamingMarkersOrHeaders()
{
Navigate(ServerPathBase);

Browser.Equal("Hello", () => Browser.Exists(By.TagName("h1")).Text);

Assert.DoesNotContain("<blazor-ssr", Browser.PageSource);

using var httpClient = new HttpClient();
using var response = await httpClient.GetAsync(new Uri(_serverFixture.RootUri, ServerPathBase));
response.EnsureSuccessStatusCode();

Assert.False(response.Content.Headers.Contains(HeaderNames.ContentEncoding));
}

[Fact]
public async Task DoesRenderStreamingPageWithStreamingHeadersToDisableBuffering()
{
using var httpClient = new HttpClient();
using var response = await httpClient.GetAsync(new Uri(_serverFixture.RootUri, $"{ServerPathBase}/streaming"), HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();

Assert.Equal("identity", response.Content.Headers.ContentEncoding.Single());
}

[Theory]
Expand Down