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

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

Fixed: Possibly multiple parsing of query string

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