2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-04-04 04:18:22 +00:00
This commit is contained in:
2026-04-02 19:42:54 +03:00
parent 4fae21deaf
commit 74830eea0c
82 changed files with 2501 additions and 3008 deletions

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.Packets.HTTP
namespace Esiur.Net.Packets.Http
{
public enum HTTPComposeOption : int
public enum HttpComposeOption : int
{
AllCalculateLength,
AllDontCalculateLength,

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.Packets.HTTP
namespace Esiur.Net.Packets.Http
{
public struct HTTPCookie
public struct HttpCookie
{
public string Name;
public string Value;
@@ -13,7 +13,7 @@ namespace Esiur.Net.Packets.HTTP
public bool HttpOnly;
public string Domain;
public HTTPCookie(string name, string value)
public HttpCookie(string name, string value)
{
Name = name;
Value = value;
@@ -23,7 +23,7 @@ namespace Esiur.Net.Packets.HTTP
Domain = null;
}
public HTTPCookie(string name, string value, DateTime expires)
public HttpCookie(string name, string value, DateTime expires)
{
Name = name;
Value = value;

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.Packets.HTTP
namespace Esiur.Net.Packets.Http
{
public enum HTTPMethod : byte
public enum HttpMethod : byte
{
GET,
POST,

View File

@@ -32,13 +32,13 @@ using Esiur.Data;
using System.Net;
using System.Text.Json.Serialization;
namespace Esiur.Net.Packets.HTTP;
public class HTTPRequestPacket : Packet
namespace Esiur.Net.Packets.Http;
public class HttpRequestPacket : Packet
{
public StringKeyList Query;
public HTTPMethod Method;
public HttpMethod Method;
public StringKeyList Headers;
public bool WSMode;
@@ -52,28 +52,28 @@ public class HTTPRequestPacket : Packet
public byte[] Message;
private HTTPMethod GetMethod(string method)
private HttpMethod GetMethod(string method)
{
switch (method.ToLower())
{
case "get":
return HTTPMethod.GET;
return HttpMethod.GET;
case "post":
return HTTPMethod.POST;
return HttpMethod.POST;
case "head":
return HTTPMethod.HEAD;
return HttpMethod.HEAD;
case "put":
return HTTPMethod.PUT;
return HttpMethod.PUT;
case "delete":
return HTTPMethod.DELETE;
return HttpMethod.DELETE;
case "options":
return HTTPMethod.OPTIONS;
return HttpMethod.OPTIONS;
case "trace":
return HTTPMethod.TRACE;
return HttpMethod.TRACE;
case "connect":
return HTTPMethod.CONNECT;
return HttpMethod.CONNECT;
default:
return HTTPMethod.UNKNOWN;
return HttpMethod.UNKNOWN;
}
}
@@ -219,7 +219,7 @@ public class HTTPRequestPacket : Packet
}
// Post Content-Length
if (Method == HTTPMethod.POST)
if (Method == HttpMethod.POST)
{
try
{

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.Packets.HTTP
namespace Esiur.Net.Packets.Http
{
public enum HTTPResponseCode : int
public enum HttpResponseCode : int
{
Switching = 101,
OK = 200,

View File

@@ -28,18 +28,18 @@ using System.Text;
using Esiur.Misc;
using Esiur.Data;
namespace Esiur.Net.Packets.HTTP;
public class HTTPResponsePacket : Packet
namespace Esiur.Net.Packets.Http;
public class HttpResponsePacket : Packet
{
public StringKeyList Headers { get; } = new StringKeyList(true);
public string Version { get; set; } = "HTTP/1.1";
public byte[] Message;
public HTTPResponseCode Number { get; set; } = HTTPResponseCode.OK;
public HttpResponseCode Number { get; set; } = HttpResponseCode.OK;
public string Text;
public List<HTTPCookie> Cookies { get; } = new List<HTTPCookie>();
public List<HttpCookie> Cookies { get; } = new List<HttpCookie>();
public bool Handled;
public override string ToString()
@@ -51,11 +51,11 @@ public class HTTPResponsePacket : Packet
+ "\n\tMessage: " + (Message != null ? Message.Length.ToString() : "NULL");
}
private string MakeHeader(HTTPComposeOption options)
private string MakeHeader(HttpComposeOption options)
{
string header = $"{Version} {(int)Number} {Text}\r\nServer: Esiur {Global.Version}\r\nDate: {DateTime.Now.ToUniversalTime().ToString("r")}\r\n";
if (options == HTTPComposeOption.AllCalculateLength)
if (options == HttpComposeOption.AllCalculateLength)
Headers["Content-Length"] = Message?.Length.ToString() ?? "0";
foreach (var kv in Headers)
@@ -75,16 +75,16 @@ public class HTTPResponsePacket : Packet
}
public bool Compose(HTTPComposeOption options)
public bool Compose(HttpComposeOption options)
{
List<byte> msg = new List<byte>();
if (options != HTTPComposeOption.DataOnly)
if (options != HttpComposeOption.DataOnly)
{
msg.AddRange(Encoding.UTF8.GetBytes(MakeHeader(options)));
}
if (options != HTTPComposeOption.SpecifiedHeadersOnly)
if (options != HttpComposeOption.SpecifiedHeadersOnly)
{
if (Message != null)
msg.AddRange(Message);
@@ -97,7 +97,7 @@ public class HTTPResponsePacket : Packet
public override bool Compose()
{
return Compose(HTTPComposeOption.AllDontCalculateLength);
return Compose(HttpComposeOption.AllDontCalculateLength);
}
public override long Parse(byte[] data, uint offset, uint ends)
@@ -129,7 +129,7 @@ public class HTTPResponsePacket : Packet
if (sMethod.Length == 3)
{
Version = sMethod[0].Trim();
Number = (HTTPResponseCode)Convert.ToInt32(sMethod[1].Trim());
Number = (HttpResponseCode)Convert.ToInt32(sMethod[1].Trim());
Text = sMethod[2];
}
@@ -163,7 +163,7 @@ public class HTTPResponsePacket : Packet
if (cookie.Length >= 1)
{
string[] splitCookie = cookie[0].Split('=');
HTTPCookie c = new HTTPCookie(splitCookie[0], splitCookie[1]);
HttpCookie c = new HttpCookie(splitCookie[0], splitCookie[1]);
for (int j = 1; j < cookie.Length; j++)
{