1 | using System.Collections.Specialized;
|
---|
2 | using SpaceWizards.HttpListener;
|
---|
3 |
|
---|
4 | namespace Webserver {
|
---|
5 | public class RequestContext {
|
---|
6 | public string RequestPath;
|
---|
7 | public readonly ERequestMethod Method;
|
---|
8 | public readonly HttpListenerRequest Request;
|
---|
9 | private NameValueCollection queryParameters;
|
---|
10 | public readonly HttpListenerResponse Response;
|
---|
11 | public readonly WebConnection Connection;
|
---|
12 | public readonly int PermissionLevel;
|
---|
13 |
|
---|
14 | public NameValueCollection QueryParameters => queryParameters ??= Request.QueryString;
|
---|
15 |
|
---|
16 | public RequestContext (string _requestPath, HttpListenerRequest _request, HttpListenerResponse _response, WebConnection _connection, int _permissionLevel) {
|
---|
17 | RequestPath = _requestPath;
|
---|
18 | Request = _request;
|
---|
19 | Response = _response;
|
---|
20 | Connection = _connection;
|
---|
21 | PermissionLevel = _permissionLevel;
|
---|
22 | Method = _request.HttpMethod switch {
|
---|
23 | "GET" => ERequestMethod.GET,
|
---|
24 | "PUT" => ERequestMethod.PUT,
|
---|
25 | "POST" => ERequestMethod.POST,
|
---|
26 | "DELETE" => ERequestMethod.DELETE,
|
---|
27 | "HEAD" => ERequestMethod.HEAD,
|
---|
28 | "OPTIONS" => ERequestMethod.OPTIONS,
|
---|
29 | _ => ERequestMethod.Other
|
---|
30 | };
|
---|
31 | }
|
---|
32 | }
|
---|
33 | }
|
---|