2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2024-06-21 16:37:48 +03:00
parent c04fc29810
commit 3a89a108db
49 changed files with 2095 additions and 1373 deletions

View File

@ -33,10 +33,11 @@ using System.Collections;
using System.Collections.Generic;
using Esiur.Net.Sockets;
using Esiur.Data;
using Esiur.Net.Packets;
using Esiur.Misc;
using System.Security.Cryptography;
using Esiur.Core;
using Esiur.Net.Packets.WebSocket;
using Esiur.Net.Packets.HTTP;
namespace Esiur.Net.HTTP;
public class HTTPConnection : NetworkConnection
@ -131,7 +132,7 @@ public class HTTPConnection : NetworkConnection
response.Headers["Sec-WebSocket-Protocol"] = request.Headers["Sec-WebSocket-Protocol"];
response.Number = HTTPResponsePacket.ResponseCode.Switching;
response.Number = HTTPResponseCode.Switching;
response.Text = "Switching Protocols";
return true;
@ -172,7 +173,7 @@ public class HTTPConnection : NetworkConnection
Send();
}
public void Send(HTTPResponsePacket.ComposeOptions Options = HTTPResponsePacket.ComposeOptions.AllCalculateLength)
public void Send(HTTPComposeOption Options = HTTPComposeOption.AllCalculateLength)
{
if (Response.Handled)
return;
@ -210,7 +211,7 @@ public class HTTPConnection : NetworkConnection
// Create a new one
session = Server.CreateSession(Global.GenerateCode(12), 60 * 20);
HTTPResponsePacket.HTTPCookie cookie = new HTTPResponsePacket.HTTPCookie("SID", session.Id);
HTTPCookie cookie = new HTTPCookie("SID", session.Id);
cookie.Expires = DateTime.MaxValue;
cookie.Path = "/";
cookie.HttpOnly = true;
@ -253,7 +254,7 @@ public class HTTPConnection : NetworkConnection
if (BL == 0)
{
if (Request.Method == HTTPRequestPacket.HTTPMethod.UNKNOWN)
if (Request.Method == HTTPMethod.UNKNOWN)
{
Close();
return;
@ -312,7 +313,7 @@ public class HTTPConnection : NetworkConnection
{
if (!Server.Execute(this))
{
Response.Number = HTTPResponsePacket.ResponseCode.InternalServerError;
Response.Number = HTTPResponseCode.InternalServerError;
Send("Bad Request");
Close();
}
@ -361,7 +362,7 @@ public class HTTPConnection : NetworkConnection
if (!File.Exists(filename))
{
Response.Number = HTTPResponsePacket.ResponseCode.NotFound;
Response.Number = HTTPResponseCode.NotFound;
Send("File Not Found");
return true;
}
@ -375,10 +376,10 @@ public class HTTPConnection : NetworkConnection
var ims = DateTime.Parse(Request.Headers["if-modified-since"]);
if ((fileEditTime - ims).TotalSeconds < 2)
{
Response.Number = HTTPResponsePacket.ResponseCode.NotModified;
Response.Number = HTTPResponseCode.NotModified;
Response.Headers.Clear();
//Response.Text = "Not Modified";
Send(HTTPResponsePacket.ComposeOptions.SpecifiedHeadersOnly);
Send(HTTPComposeOption.SpecifiedHeadersOnly);
return true;
}
}
@ -390,12 +391,12 @@ public class HTTPConnection : NetworkConnection
Response.Number = HTTPResponsePacket.ResponseCode.OK;
Response.Number = HTTPResponseCode.OK;
// Fri, 30 Oct 2007 14:19:41 GMT
Response.Headers["Last-Modified"] = fileEditTime.ToString("ddd, dd MMM yyyy HH:mm:ss");
FileInfo fi = new FileInfo(filename);
Response.Headers["Content-Length"] = fi.Length.ToString();
Send(HTTPResponsePacket.ComposeOptions.SpecifiedHeadersOnly);
Send(HTTPComposeOption.SpecifiedHeadersOnly);
//var fd = File.ReadAllBytes(filename);

View File

@ -35,12 +35,12 @@ using Esiur.Net.Sockets;
using Esiur.Data;
using Esiur.Misc;
using Esiur.Core;
using Esiur.Net.Packets;
using System.Security.Cryptography.X509Certificates;
using Esiur.Resource;
using System.Text.RegularExpressions;
using System.Linq;
using System.Reflection;
using Esiur.Net.Packets.HTTP;
namespace Esiur.Net.HTTP;
public class HTTPServer : NetworkServer<HTTPConnection>, IResource
@ -48,17 +48,17 @@ public class HTTPServer : NetworkServer<HTTPConnection>, IResource
Dictionary<string, HTTPSession> sessions = new Dictionary<string, HTTPSession>();
HTTPFilter[] filters = new HTTPFilter[0];
Dictionary<HTTPRequestPacket.HTTPMethod, List<RouteInfo>> routes = new()
Dictionary<HTTPMethod, List<RouteInfo>> routes = new()
{
[HTTPRequestPacket.HTTPMethod.GET] = new List<RouteInfo>(),
[HTTPRequestPacket.HTTPMethod.POST] = new List<RouteInfo>(),
[HTTPRequestPacket.HTTPMethod.HEAD] = new List<RouteInfo>(),
[HTTPRequestPacket.HTTPMethod.OPTIONS] = new List<RouteInfo>(),
[HTTPRequestPacket.HTTPMethod.UNKNOWN] = new List<RouteInfo>(),
[HTTPRequestPacket.HTTPMethod.DELETE] = new List<RouteInfo>(),
[HTTPRequestPacket.HTTPMethod.TRACE] = new List<RouteInfo>(),
[HTTPRequestPacket.HTTPMethod.CONNECT] = new List<RouteInfo>(),
[HTTPRequestPacket.HTTPMethod.PUT] = new List<RouteInfo>()
[HTTPMethod.GET] = new List<RouteInfo>(),
[HTTPMethod.POST] = new List<RouteInfo>(),
[HTTPMethod.HEAD] = new List<RouteInfo>(),
[HTTPMethod.OPTIONS] = new List<RouteInfo>(),
[HTTPMethod.UNKNOWN] = new List<RouteInfo>(),
[HTTPMethod.DELETE] = new List<RouteInfo>(),
[HTTPMethod.TRACE] = new List<RouteInfo>(),
[HTTPMethod.CONNECT] = new List<RouteInfo>(),
[HTTPMethod.PUT] = new List<RouteInfo>()
};
//List<RouteInfo> GetRoutes = new List<RouteInfo>();
@ -243,14 +243,14 @@ public class HTTPServer : NetworkServer<HTTPConnection>, IResource
public void MapGet(string pattern, Delegate handler)
{
var regex = Global.GetRouteRegex(pattern);
var list = routes[HTTPRequestPacket.HTTPMethod.GET];
var list = routes[HTTPMethod.GET];
list.Add(new RouteInfo(handler, regex));
}
public void MapPost(string pattern, Delegate handler)
{
var regex = Global.GetRouteRegex(pattern);
var list = routes[HTTPRequestPacket.HTTPMethod.POST];
var list = routes[HTTPMethod.POST];
list.Add(new RouteInfo(handler, regex));
}

View File

@ -17,9 +17,9 @@ public class IIPoHTTP : HTTPFilter
if (sender.Request.URL != "iip")
return new AsyncReply<bool>(false);
IIPPacket.IIPPacketAction action = (IIPPacket.IIPPacketAction)Convert.ToByte(sender.Request.Query["a"]);
IIPPacketAction action = (IIPPacketAction)Convert.ToByte(sender.Request.Query["a"]);
if (action == IIPPacket.IIPPacketAction.QueryLink)
if (action == IIPPacketAction.QueryLink)
{
EntryPoint.Query(sender.Request.Query["l"], null).Then(x =>
{

View File

@ -70,48 +70,6 @@ public class IIPoWS : HTTPFilter
return new AsyncReply<bool>(false);
/*
if (sender.Request.Filename.StartsWith("/iip/"))
{
// find the service
var path = sender.Request.Filename.Substring(5);// sender.Request.Query["path"];
Warehouse.Get(path).Then((r) =>
{
if (r is DistributedServer)
{
var httpServer = sender.Parent;
var iipServer = r as DistributedServer;
var tcpSocket = sender.Unassign();
if (tcpSocket == null)
return;
var wsSocket = new WSSocket(tcpSocket);
httpServer.RemoveConnection(sender);
//httpServer.Connections.Remove(sender);
var iipConnection = new DistributedConnection();
// iipConnection.OnReady += IipConnection_OnReady;
// iipConnection.Server = iipServer;
// iipConnection.Assign(wsSocket);
iipServer.AddConnection(iipConnection);
iipConnection.Assign(wsSocket);
wsSocket.Begin();
}
});
return true;
}
return false;
*/
}
private void IipConnection_OnReady(DistributedConnection sender)
{
Warehouse.Put(sender.RemoteUsername, sender, null, sender.Server).Wait();
}
public override AsyncReply<bool> Trigger(ResourceTrigger trigger)