Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Increase max-request-body-size to 100MB (#63)

nzbdav-devd4dcee97464f
diff --git a/backend/Program.cs b/backend/Program.cs
index 2e54482c..aa5f957d 100644
--- a/backend/Program.cs
+++ b/backend/Program.cs
@@ -1,6 +1,7 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
+using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using NWebDav.Server;
@@ -53,6 +54,8 @@ class Program
// initialize webapp
var builder = WebApplication.CreateBuilder(args);
+ var maxRequestBodySize = EnvironmentUtil.GetLongVariable("MAX_REQUEST_BODY_SIZE") ?? 100 * 1024 * 1024;
+ builder.WebHost.ConfigureKestrel(options => options.Limits.MaxRequestBodySize = maxRequestBodySize);
builder.Host.UseSerilog();
builder.Services.AddControllers();
builder.Services.AddHealthChecks();
diff --git a/backend/Utils/EnvironmentUtil.cs b/backend/Utils/EnvironmentUtil.cs
index e76c93df..4b4ef712 100644
--- a/backend/Utils/EnvironmentUtil.cs
+++ b/backend/Utils/EnvironmentUtil.cs
@@ -7,4 +7,9 @@ public static class EnvironmentUtil
return Environment.GetEnvironmentVariable(envVariable) ??
throw new Exception($"The environment variable `{envVariable}` must be set.");
}
+
+ public static long? GetLongVariable(string envVariable)
+ {
+ return long.TryParse(Environment.GetEnvironmentVariable(envVariable), out var longValue) ? longValue : null;
+ }
}
\ No newline at end of file