-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathHttpGetDelegateResource.cs
More file actions
88 lines (79 loc) · 2.98 KB
/
HttpGetDelegateResource.cs
File metadata and controls
88 lines (79 loc) · 2.98 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Threading.Tasks;
namespace Waher.Networking.HTTP
{
/// <summary>
/// HTTP resource defined by a GET delegate method.
/// </summary>
public class HttpGetDelegateResource : HttpResource, IHttpGetMethod
{
private readonly HttpAuthenticationScheme[] authenticationSchemes;
private readonly HttpMethodHandler get;
private readonly bool synchronous;
private readonly bool handlesSubPaths;
private readonly bool userSessions;
/// <summary>
/// HTTP resource defined by a GET delegate method.
/// </summary>
/// <param name="ResourceName">Name of resource.</param>
/// <param name="GET">GET 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 HttpGetDelegateResource(string ResourceName, HttpMethodHandler GET, bool Synchronous, bool HandlesSubPaths,
bool UserSessions, params HttpAuthenticationScheme[] AuthenticationSchemes)
: base(ResourceName)
{
this.get = GET;
this.synchronous = Synchronous;
this.handlesSubPaths = HandlesSubPaths;
this.authenticationSchemes = AuthenticationSchemes;
this.userSessions = UserSessions;
}
/// <summary>
/// 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).
/// </summary>
public override bool Synchronous => this.synchronous;
/// <summary>
/// If the resource handles sub-paths.
/// </summary>
public override bool HandlesSubPaths => this.handlesSubPaths;
/// <summary>
/// If the resource uses user sessions.
/// </summary>
public override bool UserSessions => this.userSessions;
/// <summary>
/// If the GET method is allowed.
/// </summary>
public bool AllowsGET
{
get
{
return !(this.get is null);
}
}
/// <summary>
/// Any authentication schemes used to authenticate users before access is granted to the corresponding resource.
/// </summary>
/// <param name="Request">Current request</param>
public override HttpAuthenticationScheme[] GetAuthenticationSchemes(HttpRequest Request)
{
return this.authenticationSchemes;
}
/// <summary>
/// Executes the GET 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 GET(HttpRequest Request, HttpResponse Response)
{
if (this.get is null)
throw new MethodNotAllowedException(this.AllowedMethods, Request);
else
return this.get(Request, Response);
}
}
}