@@ -94,6 +94,11 @@ public static void UseSpaPrerendering(
94
94
// HTML content so it can be passed as a template to the prerenderer.
95
95
RemoveConditionalRequestHeaders ( context . Request ) ;
96
96
97
+ // Make sure we're not capturing compressed content, because then we'd have
98
+ // to decompress it. Since this sub-request isn't leaving the machine, there's
99
+ // little to no benefit in having compression on it.
100
+ var originalAcceptEncodingValue = GetAndRemoveAcceptEncodingHeader ( context . Request ) ;
101
+
97
102
// Capture the non-prerendered responses, which in production will typically only
98
103
// be returning the default SPA index.html page (because other resources will be
99
104
// served statically from disk). We will use this as a template in which to inject
@@ -111,6 +116,11 @@ public static void UseSpaPrerendering(
111
116
finally
112
117
{
113
118
context . Response . Body = originalResponseStream ;
119
+
120
+ if ( ! string . IsNullOrEmpty ( originalAcceptEncodingValue ) )
121
+ {
122
+ context . Request . Headers [ HeaderNames . AcceptEncoding ] = originalAcceptEncodingValue ;
123
+ }
114
124
}
115
125
116
126
// If it isn't an HTML page that we can use as the template for prerendering,
@@ -181,6 +191,20 @@ private static void RemoveConditionalRequestHeaders(HttpRequest request)
181
191
request . Headers . Remove ( HeaderNames . IfRange ) ;
182
192
}
183
193
194
+ private static string GetAndRemoveAcceptEncodingHeader ( HttpRequest request )
195
+ {
196
+ var headers = request . Headers ;
197
+ var value = ( string ) null ;
198
+
199
+ if ( headers . ContainsKey ( HeaderNames . AcceptEncoding ) )
200
+ {
201
+ value = headers [ HeaderNames . AcceptEncoding ] ;
202
+ headers . Remove ( HeaderNames . AcceptEncoding ) ;
203
+ }
204
+
205
+ return value ;
206
+ }
207
+
184
208
private static ( string , string ) GetUnencodedUrlAndPathQuery ( HttpContext httpContext )
185
209
{
186
210
// This is a duplicate of code from Prerenderer.cs in the SpaServices package.
0 commit comments