forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetStatusAttribute.cs
More file actions
34 lines (28 loc) · 1.04 KB
/
SetStatusAttribute.cs
File metadata and controls
34 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Net;
using ServiceStack.ServiceHost;
namespace ServiceStack.ServiceInterface
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class SetStatusAttribute : RequestFilterAttribute
{
public int? Status { get; set; }
public HttpStatusCode? StatusCode { get; set; }
public string Description { get; set; }
public SetStatusAttribute() {}
public SetStatusAttribute(int status, string description)
{
Status = status;
Description = description;
}
public SetStatusAttribute(HttpStatusCode statusCode, string description)
: this((int)statusCode, description) {}
public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
{
if (Status.HasValue)
res.StatusCode = Status.Value;
if (!string.IsNullOrEmpty(Description))
res.StatusDescription = Description;
}
}
}