diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-19 22:52:01 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-08-19 22:52:01 +0800 |
commit | 577d282f8e8f44f1a48b9dbf7dd90e8ef50c7a53 (patch) | |
tree | 5725e61da570be86173472d68bd6df521e593b65 /Timeline/Filters | |
parent | 134173eda92de04961dc69757b257c1c547d88a4 (diff) | |
download | timeline-577d282f8e8f44f1a48b9dbf7dd90e8ef50c7a53.tar.gz timeline-577d282f8e8f44f1a48b9dbf7dd90e8ef50c7a53.tar.bz2 timeline-577d282f8e8f44f1a48b9dbf7dd90e8ef50c7a53.zip |
Add check for content in avatar put.
Diffstat (limited to 'Timeline/Filters')
-rw-r--r-- | Timeline/Filters/ContentHeaderAttributes.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Timeline/Filters/ContentHeaderAttributes.cs b/Timeline/Filters/ContentHeaderAttributes.cs new file mode 100644 index 00000000..14685a01 --- /dev/null +++ b/Timeline/Filters/ContentHeaderAttributes.cs @@ -0,0 +1,48 @@ +using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Filters;
+using Timeline.Models.Http;
+
+namespace Timeline.Filters
+{
+ public class RequireContentTypeAttribute : ActionFilterAttribute
+ {
+ public override void OnActionExecuting(ActionExecutingContext context)
+ {
+ if (context.HttpContext.Request.ContentType == null)
+ {
+ context.Result = new BadRequestObjectResult(CommonResponse.MissingContentType());
+ }
+ }
+ }
+
+ public class RequireContentLengthAttribute : ActionFilterAttribute
+ {
+ public RequireContentLengthAttribute()
+ : this(true)
+ {
+
+ }
+
+ public RequireContentLengthAttribute(bool requireNonZero)
+ {
+ RequireNonZero = requireNonZero;
+ }
+
+ public bool RequireNonZero { get; set; }
+
+ public override void OnActionExecuting(ActionExecutingContext context)
+ {
+ if (context.HttpContext.Request.ContentLength == null)
+ {
+ context.Result = new BadRequestObjectResult(CommonResponse.MissingContentLength());
+ return;
+ }
+
+ if (RequireNonZero && context.HttpContext.Request.ContentLength.Value == 0)
+ {
+ context.Result = new BadRequestObjectResult(CommonResponse.ZeroContentLength());
+ return;
+ }
+ }
+ }
+}
|