[391] | 1 | using SpaceWizards.HttpListener;
|
---|
| 2 |
|
---|
| 3 | namespace Webserver {
|
---|
[415] | 4 | public enum ERequestMethod {
|
---|
| 5 | Other,
|
---|
| 6 | // ReSharper disable InconsistentNaming
|
---|
| 7 | GET,
|
---|
| 8 | PUT,
|
---|
| 9 | POST,
|
---|
| 10 | DELETE,
|
---|
| 11 | HEAD,
|
---|
| 12 | OPTIONS,
|
---|
| 13 | // ReSharper restore InconsistentNaming
|
---|
| 14 | Count
|
---|
| 15 | }
|
---|
| 16 |
|
---|
[391] | 17 | public class RequestContext {
|
---|
| 18 | public string RequestPath;
|
---|
[415] | 19 | public readonly ERequestMethod Method;
|
---|
[391] | 20 | public readonly HttpListenerRequest Request;
|
---|
| 21 | public readonly HttpListenerResponse Response;
|
---|
| 22 | public readonly WebConnection Connection;
|
---|
| 23 | public readonly int PermissionLevel;
|
---|
| 24 |
|
---|
| 25 | public RequestContext (string _requestPath, HttpListenerRequest _request, HttpListenerResponse _response, WebConnection _connection, int _permissionLevel) {
|
---|
| 26 | RequestPath = _requestPath;
|
---|
| 27 | Request = _request;
|
---|
| 28 | Response = _response;
|
---|
| 29 | Connection = _connection;
|
---|
| 30 | PermissionLevel = _permissionLevel;
|
---|
[415] | 31 | Method = _request.HttpMethod switch {
|
---|
| 32 | "GET" => ERequestMethod.GET,
|
---|
| 33 | "PUT" => ERequestMethod.PUT,
|
---|
| 34 | "POST" => ERequestMethod.POST,
|
---|
| 35 | "DELETE" => ERequestMethod.DELETE,
|
---|
| 36 | "HEAD" => ERequestMethod.HEAD,
|
---|
| 37 | "OPTIONS" => ERequestMethod.OPTIONS,
|
---|
| 38 | _ => ERequestMethod.Other
|
---|
| 39 | };
|
---|
[391] | 40 | }
|
---|
| 41 | }
|
---|
| 42 | }
|
---|