[471] | 1 | using System.Collections.Specialized;
|
---|
[391] | 2 | using SpaceWizards.HttpListener;
|
---|
| 3 |
|
---|
| 4 | namespace Webserver {
|
---|
| 5 | public class RequestContext {
|
---|
| 6 | public string RequestPath;
|
---|
[415] | 7 | public readonly ERequestMethod Method;
|
---|
[391] | 8 | public readonly HttpListenerRequest Request;
|
---|
[471] | 9 | private NameValueCollection queryParameters;
|
---|
[391] | 10 | public readonly HttpListenerResponse Response;
|
---|
| 11 | public readonly WebConnection Connection;
|
---|
| 12 | public readonly int PermissionLevel;
|
---|
| 13 |
|
---|
[471] | 14 | public NameValueCollection QueryParameters => queryParameters ??= Request.QueryString;
|
---|
| 15 |
|
---|
[391] | 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;
|
---|
[415] | 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 | };
|
---|
[391] | 31 | }
|
---|
| 32 | }
|
---|
| 33 | }
|
---|