source: TFP-WebServer/WebServer/src/RequestContext.cs@ 477

Last change on this file since 477 was 471, checked in by alloc, 15 months ago

Fixed: Possibly multiple parsing of query string

File size: 1.1 KB
RevLine 
[471]1using System.Collections.Specialized;
[391]2using SpaceWizards.HttpListener;
3
4namespace 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}
Note: See TracBrowser for help on using the repository browser.