-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathHttpGetPostDelegateResource.cs
More file actions
55 lines (51 loc) · 1.97 KB
/
HttpGetPostDelegateResource.cs
File metadata and controls
55 lines (51 loc) · 1.97 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Threading.Tasks;
namespace Waher.Networking.HTTP
{
/// <summary>
/// HTTP resource defined by GET and POST delegate methods.
/// </summary>
public class HttpGetPostDelegateResource : HttpGetDelegateResource, IHttpPostMethod
{
private readonly HttpMethodHandler post;
/// <summary>
/// HTTP resource defined by GET and POST delegate methods.
/// </summary>
/// <param name="ResourceName">Name of resource.</param>
/// <param name="GET">GET Method.</param>
/// <param name="POST">POST Method.</param>
/// <param name="Synchronous">If the resource is synchronous (i.e. returns a response in the method handler), or if it is asynchronous
/// (i.e. sends the response from another thread).</param>
/// <param name="HandlesSubPaths">If sub-paths are handled.</param>
/// <param name="UserSessions">If the resource uses user sessions.</param>
/// <param name="AuthenticationSchemes">Any authentication schemes used to authenticate users before access is granted.</param>
public HttpGetPostDelegateResource(string ResourceName, HttpMethodHandler GET, HttpMethodHandler POST, bool Synchronous, bool HandlesSubPaths,
bool UserSessions, params HttpAuthenticationScheme[] AuthenticationSchemes)
: base(ResourceName, GET, Synchronous, HandlesSubPaths, UserSessions, AuthenticationSchemes)
{
this.post = POST;
}
/// <summary>
/// If the POST method is allowed.
/// </summary>
public bool AllowsPOST
{
get
{
return !(this.post is null);
}
}
/// <summary>
/// Executes the POST method on the resource.
/// </summary>
/// <param name="Request">HTTP Request</param>
/// <param name="Response">HTTP Response</param>
/// <exception cref="HttpException">If an error occurred when processing the method.</exception>
public Task POST(HttpRequest Request, HttpResponse Response)
{
if (this.post is null)
throw new MethodNotAllowedException(this.AllowedMethods, Request);
else
return this.post(Request, Response);
}
}
}