mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using Squidex.Domain.Apps.Entities.Assets;
|
|
|
|
namespace Squidex.Web
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
|
public sealed class AssetRequestSizeLimitAttribute : Attribute, IAuthorizationFilter, IRequestSizePolicy
|
|
{
|
|
public void OnAuthorization(AuthorizationFilterContext context)
|
|
{
|
|
var assetOptions = context.HttpContext.RequestServices.GetService<IOptions<AssetOptions>>();
|
|
|
|
var maxRequestBodySizeFeature = context.HttpContext.Features.Get<IHttpMaxRequestBodySizeFeature>();
|
|
|
|
if (maxRequestBodySizeFeature?.IsReadOnly == false)
|
|
{
|
|
if (assetOptions?.Value.MaxSize > 0)
|
|
{
|
|
maxRequestBodySizeFeature.MaxRequestBodySize = assetOptions.Value.MaxSize;
|
|
}
|
|
else
|
|
{
|
|
maxRequestBodySizeFeature.MaxRequestBodySize = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|