Skip to content

Commit a6a87e3

Browse files
Fix error with aspnet core compression on large response (#114)
Co-authored-by: claudia <cmurialdo@gmail.com>
1 parent 2737b15 commit a6a87e3

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

dotnet/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<MinorFileVersion>5</MinorFileVersion>
77
<RevisionFileVersion Condition="'$(CommitNumber)'!=''">$(CommitNumber)</RevisionFileVersion>
88
<RevisionFileVersion Condition="'$(CommitNumber)'==''">0</RevisionFileVersion>
9-
<FileVersionWithoutRevision>$(MajorFileVersion).$(MinorFileVersion).2</FileVersionWithoutRevision>
9+
<FileVersionWithoutRevision>$(MajorFileVersion).$(MinorFileVersion).3</FileVersionWithoutRevision>
1010
<FileVersion>$(FileVersionWithoutRevision).$(RevisionFileVersion)</FileVersion>
1111
<InformationalVersion>$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss")).$(GITHUB_SHA)</InformationalVersion>
1212
<Company>GeneXus</Company>

dotnet/src/dotnetcore/GxClasses/Helpers/HtmlHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public void Write(string s) {
1919
}
2020
public void Flush()
2121
{
22-
_context.Response.WriteAsync(_stream.ToString());
22+
//Response.WriteAsync makes ResponseCompressor throws exception for big stream, use Response.Body.Write instead
23+
_context.Response.Body.Write(Encoding.UTF8.GetBytes(_stream.ToString()));
24+
_context.Response.Body.FlushAsync();
2325
}
2426
}
2527

dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using Microsoft.AspNetCore.Hosting;
1919
using Microsoft.AspNetCore.Http;
2020
using Microsoft.AspNetCore.Mvc;
21-
using Microsoft.AspNetCore.ResponseCompression;
2221
using Microsoft.AspNetCore.Routing;
2322
using Microsoft.AspNetCore.Server.Kestrel.Core;
2423
using Microsoft.AspNetCore.StaticFiles;
@@ -206,13 +205,14 @@ public void ConfigureServices(IServiceCollection services)
206205
options.Cookie.HttpOnly = true;
207206
});
208207

209-
services.Configure<GzipCompressionProviderOptions>(options =>
210-
options.Level = System.IO.Compression.CompressionLevel.Fastest);
208+
211209
services.AddDirectoryBrowser();
212-
services.AddResponseCompression(options =>
210+
if (GXUtil.CompressResponse())
213211
{
214-
options.MimeTypes = new[]
212+
services.AddResponseCompression(options =>
215213
{
214+
options.MimeTypes = new[]
215+
{
216216
// Default
217217
"text/plain",
218218
"text/css",
@@ -225,8 +225,10 @@ public void ConfigureServices(IServiceCollection services)
225225
// Custom
226226
"application/json",
227227
"application/pdf"
228-
};
229-
});
228+
};
229+
options.EnableForHttps = true;
230+
});
231+
}
230232
services.AddMvc();
231233
}
232234
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
@@ -251,8 +253,10 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
251253
provider.Mappings[".usdz"] = "model/vnd.pixar.usd";
252254
provider.Mappings[".sfb"] = "model/sfb";
253255
provider.Mappings[".gltf"] = "model/gltf+json";
254-
255-
app.UseResponseCompression();
256+
if (GXUtil.CompressResponse())
257+
{
258+
app.UseResponseCompression();
259+
}
256260
app.UseCookiePolicy();
257261
app.UseSession();
258262
app.UseStaticFiles();

0 commit comments

Comments
 (0)