Skip to content

Commit

Permalink
init constructors variables on Request.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed Nov 15, 2023
1 parent 70f3bda commit 5ef7640
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/HTTP/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,77 @@ public class Request
public Request(HttpListenerRequest httpListenerRequest)
{
RawRequest = httpListenerRequest;

#region Headers

Headers = new KeyValueContainer();

if (RawRequest.Headers.Count > 0)
{
foreach (var key in RawRequest.Headers.AllKeys)
{
string value = RawRequest.Headers[key] ?? string.Empty;
Headers.Add(key, value);
}
}

#endregion

#region Queries

Queries = new KeyValueContainer();

if (RawRequest.QueryString.Count > 0)
{
foreach (var key in RawRequest.QueryString.AllKeys)
{
string value = RawRequest.QueryString[key] ?? string.Empty;
Queries.Add(key, value);
}
}

#endregion

#region Cookies

var cookiesList = new List<Cookie>();

if (RawRequest.Cookies.Count > 0)
{
foreach (var cookie in RawRequest.Cookies)
{
cookiesList.Add((Cookie)cookie);
}
}

Cookies = cookiesList.ToArray();

#endregion

Method = new HttpMethod(RawRequest.HttpMethod);

Url = RawRequest.Url.AbsoluteUri;

Path = RawRequest.Url.LocalPath;

LocalEndPoint = new Host(RawRequest.LocalEndPoint);

RemoteEndPoint = new Host(RawRequest.RemoteEndPoint);

IsWebSocket = RawRequest.IsWebSocketRequest;

IsLocalRequest = RawRequest.IsLocal;

IsEncrypted = RawRequest.IsSecureConnection;
}


public bool ComparePath(string path)
{
if (string.IsNullOrWhiteSpace(path)) return false;
if (string.IsNullOrWhiteSpace(Path)) return false;

return Path.Trim() == path.Trim();
}
}
}

0 comments on commit 5ef7640

Please sign in to comment.