aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Filters
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline/Filters')
-rw-r--r--Timeline/Filters/Header.cs63
-rw-r--r--Timeline/Filters/Timeline.cs32
2 files changed, 0 insertions, 95 deletions
diff --git a/Timeline/Filters/Header.cs b/Timeline/Filters/Header.cs
deleted file mode 100644
index cc5ddd9f..00000000
--- a/Timeline/Filters/Header.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Filters;
-using Timeline.Models.Http;
-
-namespace Timeline.Filters
-{
- /// <summary>
- /// Restrict max content length.
- /// </summary>
- public class MaxContentLengthFilter : IResourceFilter
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="maxByteLength">Max length.</param>
- public MaxContentLengthFilter(long maxByteLength)
- {
- MaxByteLength = maxByteLength;
- }
-
- /// <summary>
- /// Max length.
- /// </summary>
- public long MaxByteLength { get; set; }
-
- /// <inheritdoc/>
- public void OnResourceExecuted(ResourceExecutedContext context)
- {
- }
-
- /// <inheritdoc/>
- public void OnResourceExecuting(ResourceExecutingContext context)
- {
- var contentLength = context.HttpContext.Request.ContentLength;
- if (contentLength != null && contentLength > MaxByteLength)
- {
- context.Result = new BadRequestObjectResult(ErrorResponse.Common.Content.TooBig(MaxByteLength + "B"));
- }
- }
- }
-
- /// <summary>
- /// Restrict max content length.
- /// </summary>
- public class MaxContentLengthAttribute : TypeFilterAttribute
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="maxByteLength">Max length.</param>
- public MaxContentLengthAttribute(long maxByteLength)
- : base(typeof(MaxContentLengthFilter))
- {
- MaxByteLength = maxByteLength;
- Arguments = new object[] { maxByteLength };
- }
-
- /// <summary>
- /// Max length.
- /// </summary>
- public long MaxByteLength { get; }
- }
-}
diff --git a/Timeline/Filters/Timeline.cs b/Timeline/Filters/Timeline.cs
deleted file mode 100644
index 6a730ee7..00000000
--- a/Timeline/Filters/Timeline.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Filters;
-using Timeline.Models.Http;
-using Timeline.Services.Exceptions;
-
-namespace Timeline.Filters
-{
- public class CatchTimelineNotExistExceptionAttribute : ExceptionFilterAttribute
- {
- public override void OnException(ExceptionContext context)
- {
- if (context.Exception is TimelineNotExistException e)
- {
- if (e.InnerException is UserNotExistException)
- {
- if (HttpMethods.IsGet(context.HttpContext.Request.Method))
- context.Result = new NotFoundObjectResult(ErrorResponse.UserCommon.NotExist());
- else
- context.Result = new BadRequestObjectResult(ErrorResponse.UserCommon.NotExist());
- }
- else
- {
- if (HttpMethods.IsGet(context.HttpContext.Request.Method))
- context.Result = new NotFoundObjectResult(ErrorResponse.TimelineController.NotExist());
- else
- context.Result = new BadRequestObjectResult(ErrorResponse.TimelineController.NotExist());
- }
- }
- }
- }
-}