diff --git a/.vs/Tesses.WebServer/xs/UserPrefs.xml b/.vs/Tesses.WebServer/xs/UserPrefs.xml index 0e52cc4..d075d3b 100644 --- a/.vs/Tesses.WebServer/xs/UserPrefs.xml +++ b/.vs/Tesses.WebServer/xs/UserPrefs.xml @@ -1,28 +1,25 @@  - + - - - + + - - - - + + + - diff --git a/Tesses.WebServer.Console/Program.cs b/Tesses.WebServer.Console/Program.cs index 80756ef..84f10c5 100644 --- a/Tesses.WebServer.Console/Program.cs +++ b/Tesses.WebServer.Console/Program.cs @@ -1,56 +1,57 @@ -using Tesses; -using Tesses.WebServer; -namespace Tesses.WebServer.ConsoleApp -{ - - class MainClass - { - public static void Main(string[] args) - { - TestObject some_object = new TestObject(); - RouteServer rserver = new RouteServer(); - rserver.Add("/", async(ctx) => { - await ctx.SendJsonAsync(some_object); - }); - rserver.Add("/page", async(ctx) => { - await ctx.SendTextAsync("Demetria Devonne Lovato 8/20/1992"); - }); - - var ip=System.Net.IPAddress.Any; - StaticServer static_server = new StaticServer(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyVideos)); - MountableServer mountable = new MountableServer(static_server); - - mountable.Mount("/api/",new DynamicServer()); - BasicAuthServer basicAuth = new BasicAuthServer((user, pass) => { return user == "demi" && pass == "password123"; }, rserver, "RouteServer"); //bad pasword I know, This is a sample - mountable.Mount("/api/route/",basicAuth); - - HttpServerListener s = new HttpServerListener(new System.Net.IPEndPoint(ip, 24240),mountable); - - /* - So this sample application - Route Server (Like dajuric/simple-http's routes (uses modified code from that project)) - (In this example It is password protected, Username: "demi", Password: "password123") - I know password123 is a bad password (but its ok for this sample project) - - /api/route/page: shows authors favorite artist and the birthday - /api/route/: shows authors name, birthday, gender - Dynamic Server (native api) - /api/rand: shows how you can use query params - /api/count: counts up every time you go to it - - everything else is files in My Videos - */ - - s.ListenAsync(System.Threading.CancellationToken.None).Wait(); - } - - public class TestObject - { - public string name => "Mike Nolan"; - public int month => 12; - public int day => 2; - public int year => 2000; - public string gender => "Male"; //duh - } - } -} +using Tesses; +using Tesses.WebServer; +namespace Tesses.WebServer.ConsoleApp +{ + + class MainClass + { + public static void Main(string[] args) + { + TestObject some_object = new TestObject(); + RouteServer rserver = new RouteServer(); + rserver.Add("/", async(ctx) => { + await ctx.SendJsonAsync(some_object); + }); + rserver.Add("/page", async(ctx) => { + await ctx.SendTextAsync("Demetria Devonne Lovato 8/20/1992"); + }); + + var ip=System.Net.IPAddress.Any; + StaticServer static_server = new StaticServer(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyVideos)); + MountableServer mountable = new MountableServer(static_server); + + mountable.Mount("/api/",new DynamicServer()); + BasicAuthServer basicAuth = new BasicAuthServer((user, pass) => { return user == "demi" && pass == "password123"; }, rserver, "RouteServer"); //bad pasword I know, This is a sample + mountable.Mount("/api/route/",basicAuth); + + HttpServerListener s = new HttpServerListener(new System.Net.IPEndPoint(ip, 24240),mountable); + + /* + So this sample application + Route Server (Like dajuric/simple-http's routes (uses modified code from that project)) + (In this example It is password protected, Username: "demi", Password: "password123") + I know password123 is a bad password (but its ok for this sample project) + + /api/route/page: shows authors favorite artist and the birthday + /api/route/: shows authors name, birthday, gender + Dynamic Server (native api) + /api/rand: shows how you can use query params + /api/count: counts up every time you go to it + + everything else is files in My Videos + */ + + s.ListenAsync(System.Threading.CancellationToken.None).Wait(); + } + + public class TestObject + { + public string name => "Mike Nolan"; + public int month => 12; + public int day => 2; + public int year => 2000; + public string gender => "Male"; //duh + } + } +} + diff --git a/Tesses.WebServer.Console/Properties/AssemblyInfo.cs b/Tesses.WebServer.Console/Properties/AssemblyInfo.cs deleted file mode 100644 index 81ee792..0000000 --- a/Tesses.WebServer.Console/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("Tesses.WebServer.Console")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("${AuthorCopyright}")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] diff --git a/Tesses.WebServer.Console/Server.cs b/Tesses.WebServer.Console/Server.cs index 30be29d..d8e95b0 100644 --- a/Tesses.WebServer.Console/Server.cs +++ b/Tesses.WebServer.Console/Server.cs @@ -83,3 +83,4 @@ namespace Tesses.WebServer.ConsoleApp } } } + diff --git a/Tesses.WebServer.Console/Tesses.WebServer.Console.csproj b/Tesses.WebServer.Console/Tesses.WebServer.Console.csproj index 8da4f74..aee68de 100644 --- a/Tesses.WebServer.Console/Tesses.WebServer.Console.csproj +++ b/Tesses.WebServer.Console/Tesses.WebServer.Console.csproj @@ -1,55 +1,14 @@ - - + + + + + + - Debug - x86 - {3E464D71-CC54-4E71-9C8F-60B0ADF11EC1} Exe - Tesses.WebServer.Console - Tesses.WebServer.Console - v4.7 + net6.0 + enable + enable - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - true - x86 - - - true - bin\Release - prompt - 4 - true - x86 - - - - - ..\packages\MimeTypesMap.1.0.8\lib\net452\MimeTypesMap.dll - - - ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll - - - - - - - - - - {24949E8A-6661-4853-B2A2-FC957C1B58C3} - Tesses.WebServer - - - - - - - \ No newline at end of file + + diff --git a/Tesses.WebServer.Console/packages.config b/Tesses.WebServer.Console/packages.config deleted file mode 100644 index 5feed8f..0000000 --- a/Tesses.WebServer.Console/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Tesses.WebServer/ServerContext.cs b/Tesses.WebServer.NetStandard/ServerContext.cs similarity index 100% rename from Tesses.WebServer/ServerContext.cs rename to Tesses.WebServer.NetStandard/ServerContext.cs diff --git a/Tesses.WebServer/SimpleHttpCode.cs b/Tesses.WebServer.NetStandard/SimpleHttpCode.cs similarity index 100% rename from Tesses.WebServer/SimpleHttpCode.cs rename to Tesses.WebServer.NetStandard/SimpleHttpCode.cs diff --git a/Tesses.WebServer/StatusCodeMap.cs b/Tesses.WebServer.NetStandard/StatusCodeMap.cs similarity index 100% rename from Tesses.WebServer/StatusCodeMap.cs rename to Tesses.WebServer.NetStandard/StatusCodeMap.cs diff --git a/Tesses.WebServer.NetStandard/Tesses.WebServer.NetStandard.csproj b/Tesses.WebServer.NetStandard/Tesses.WebServer.NetStandard.csproj new file mode 100644 index 0000000..795363e --- /dev/null +++ b/Tesses.WebServer.NetStandard/Tesses.WebServer.NetStandard.csproj @@ -0,0 +1,19 @@ + + + + netstandard2.0 + Tesses.WebServer + Mike Nolan + Tesses + A TCP Listener HTTP(s) Server + MIT + HTTP, WebServer, Website + https://gitlab.tesses.cf/tesses50/tesses.webserver + + + + + + + + diff --git a/Tesses.WebServer/TessesServer.cs b/Tesses.WebServer.NetStandard/TessesServer.cs similarity index 97% rename from Tesses.WebServer/TessesServer.cs rename to Tesses.WebServer.NetStandard/TessesServer.cs index cdab2e4..86deee9 100644 --- a/Tesses.WebServer/TessesServer.cs +++ b/Tesses.WebServer.NetStandard/TessesServer.cs @@ -11,6 +11,7 @@ using HeyRed.Mime; using Newtonsoft.Json; using System.Security.Cryptography.X509Certificates; using System.Net.Security; +using System.Security.Authentication; namespace Tesses.WebServer { @@ -172,7 +173,7 @@ namespace Tesses.WebServer public override async Task GetAsync(ServerContext ctx) { string someUrl = Path.Combine(_path,WebUtility.UrlDecode(ctx.UrlPath.Substring(1)).Replace('/', Path.DirectorySeparatorChar)); - Console.WriteLine(someUrl); + //Console.WriteLine(someUrl); if (Directory.Exists(someUrl)) { string name; @@ -490,28 +491,35 @@ namespace Tesses.WebServer public sealed class HttpServerListener { + public bool PrintUrls {get;set;} bool https; X509Certificate cert; IServer _server; TcpListener _listener; + SslProtocols protocols; + // public HttpServerListener(IPEndPoint endPoint,IServer server) { _listener = new TcpListener(endPoint); _server = server; https = false; + PrintUrls=false; } public HttpServerListener(IServer server) { _listener = new TcpListener(new IPEndPoint(IPAddress.Any, 3251)); _server = server; https = false; + PrintUrls=false; } - public HttpServerListener(IPEndPoint endpoint,IServer server,X509Certificate cert) + public HttpServerListener(IPEndPoint endpoint,IServer server,X509Certificate cert,SslProtocols protocols=SslProtocols.Default) { _listener = new TcpListener(endpoint); _server = server; https = cert != null; this.cert = cert; + this.protocols=protocols; + PrintUrls=false; } public async Task ListenAsync(CancellationToken token) { @@ -571,7 +579,7 @@ namespace Tesses.WebServer clt.GetStream(), false); try { - sslStream.AuthenticateAsServer(cert, clientCertificateRequired: false, checkCertificateRevocation: true); + sslStream.AuthenticateAsServer(cert,false,protocols,true); } catch (Exception ex) @@ -613,6 +621,10 @@ namespace Tesses.WebServer ctx.Server = clt.Client.LocalEndPoint as IPEndPoint; ctx.Client = clt.Client.RemoteEndPoint as IPEndPoint; _server.AddCors(ctx); + if(PrintUrls) + { + Console.WriteLine(path); + } if (!await _server.BeforeAsync(ctx)) { switch (method) diff --git a/Tesses.WebServer.sln b/Tesses.WebServer.sln index f467bda..f42256a 100644 --- a/Tesses.WebServer.sln +++ b/Tesses.WebServer.sln @@ -1,23 +1,28 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tesses.WebServer.Console", "Tesses.WebServer.Console\Tesses.WebServer.Console.csproj", "{3E464D71-CC54-4E71-9C8F-60B0ADF11EC1}" +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tesses.WebServer.Console", "Tesses.WebServer.Console\Tesses.WebServer.Console.csproj", "{5DC1CAC9-0F1B-4715-B4B5-6115E16823E0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tesses.WebServer", "Tesses.WebServer\Tesses.WebServer.csproj", "{24949E8A-6661-4853-B2A2-FC957C1B58C3}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tesses.WebServer.NetStandard", "Tesses.WebServer.NetStandard\Tesses.WebServer.NetStandard.csproj", "{C76507C5-D30C-46CB-A527-5CF7090CAED6}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3E464D71-CC54-4E71-9C8F-60B0ADF11EC1}.Debug|x86.ActiveCfg = Debug|x86 - {3E464D71-CC54-4E71-9C8F-60B0ADF11EC1}.Debug|x86.Build.0 = Debug|x86 - {3E464D71-CC54-4E71-9C8F-60B0ADF11EC1}.Release|x86.ActiveCfg = Release|x86 - {3E464D71-CC54-4E71-9C8F-60B0ADF11EC1}.Release|x86.Build.0 = Release|x86 - {24949E8A-6661-4853-B2A2-FC957C1B58C3}.Debug|x86.ActiveCfg = Debug|Any CPU - {24949E8A-6661-4853-B2A2-FC957C1B58C3}.Debug|x86.Build.0 = Debug|Any CPU - {24949E8A-6661-4853-B2A2-FC957C1B58C3}.Release|x86.ActiveCfg = Release|Any CPU - {24949E8A-6661-4853-B2A2-FC957C1B58C3}.Release|x86.Build.0 = Release|Any CPU + {5DC1CAC9-0F1B-4715-B4B5-6115E16823E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5DC1CAC9-0F1B-4715-B4B5-6115E16823E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5DC1CAC9-0F1B-4715-B4B5-6115E16823E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5DC1CAC9-0F1B-4715-B4B5-6115E16823E0}.Release|Any CPU.Build.0 = Release|Any CPU + {C76507C5-D30C-46CB-A527-5CF7090CAED6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C76507C5-D30C-46CB-A527-5CF7090CAED6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C76507C5-D30C-46CB-A527-5CF7090CAED6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C76507C5-D30C-46CB-A527-5CF7090CAED6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Tesses.WebServer/Properties/AssemblyInfo.cs b/Tesses.WebServer/Properties/AssemblyInfo.cs deleted file mode 100644 index d0fa19d..0000000 --- a/Tesses.WebServer/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("Tesses.WebServer")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("${AuthorCopyright}")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] diff --git a/Tesses.WebServer/Tesses.WebServer.csproj b/Tesses.WebServer/Tesses.WebServer.csproj deleted file mode 100644 index f9afa76..0000000 --- a/Tesses.WebServer/Tesses.WebServer.csproj +++ /dev/null @@ -1,49 +0,0 @@ - - - - Debug - AnyCPU - {24949E8A-6661-4853-B2A2-FC957C1B58C3} - Library - Tesses.WebServer - Tesses.WebServer - v4.7 - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - true - bin\Release - prompt - 4 - false - - - - - ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll - - - ..\packages\MimeTypesMap.1.0.8\lib\net452\MimeTypesMap.dll - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Tesses.WebServer/packages.config b/Tesses.WebServer/packages.config deleted file mode 100644 index 5feed8f..0000000 --- a/Tesses.WebServer/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file