mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
When capturing prerendering template, avoid problems with HTTP compression
This commit is contained in:
@@ -94,6 +94,11 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
// HTML content so it can be passed as a template to the prerenderer.
|
// HTML content so it can be passed as a template to the prerenderer.
|
||||||
RemoveConditionalRequestHeaders(context.Request);
|
RemoveConditionalRequestHeaders(context.Request);
|
||||||
|
|
||||||
|
// Make sure we're not capturing compressed content, because then we'd have
|
||||||
|
// to decompress it. Since this sub-request isn't leaving the machine, there's
|
||||||
|
// little to no benefit in having compression on it.
|
||||||
|
var originalAcceptEncodingValue = GetAndRemoveAcceptEncodingHeader(context.Request);
|
||||||
|
|
||||||
// Capture the non-prerendered responses, which in production will typically only
|
// Capture the non-prerendered responses, which in production will typically only
|
||||||
// be returning the default SPA index.html page (because other resources will be
|
// be returning the default SPA index.html page (because other resources will be
|
||||||
// served statically from disk). We will use this as a template in which to inject
|
// served statically from disk). We will use this as a template in which to inject
|
||||||
@@ -111,6 +116,11 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
context.Response.Body = originalResponseStream;
|
context.Response.Body = originalResponseStream;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(originalAcceptEncodingValue))
|
||||||
|
{
|
||||||
|
context.Request.Headers[HeaderNames.AcceptEncoding] = originalAcceptEncodingValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it isn't an HTML page that we can use as the template for prerendering,
|
// If it isn't an HTML page that we can use as the template for prerendering,
|
||||||
@@ -181,6 +191,20 @@ namespace Microsoft.AspNetCore.Builder
|
|||||||
request.Headers.Remove(HeaderNames.IfRange);
|
request.Headers.Remove(HeaderNames.IfRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetAndRemoveAcceptEncodingHeader(HttpRequest request)
|
||||||
|
{
|
||||||
|
var headers = request.Headers;
|
||||||
|
var value = (string)null;
|
||||||
|
|
||||||
|
if (headers.ContainsKey(HeaderNames.AcceptEncoding))
|
||||||
|
{
|
||||||
|
value = headers[HeaderNames.AcceptEncoding];
|
||||||
|
headers.Remove(HeaderNames.AcceptEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
private static (string, string) GetUnencodedUrlAndPathQuery(HttpContext httpContext)
|
private static (string, string) GetUnencodedUrlAndPathQuery(HttpContext httpContext)
|
||||||
{
|
{
|
||||||
// This is a duplicate of code from Prerenderer.cs in the SpaServices package.
|
// This is a duplicate of code from Prerenderer.cs in the SpaServices package.
|
||||||
|
|||||||
Reference in New Issue
Block a user