Converted to NET Standard 2.0

This commit is contained in:
Michael Nolan 2022-04-03 10:36:38 -05:00
parent dc581343a4
commit 9244284c44
15 changed files with 128 additions and 245 deletions

View File

@ -1,28 +1,25 @@
<Properties StartupConfiguration="{3E464D71-CC54-4E71-9C8F-60B0ADF11EC1}|Default">
<MonoDevelop.Ide.Workbench ActiveDocument="Tesses.WebServer.Console/Program.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Tesses.WebServer/TessesServer.cs">
<Files>
<File FileName="Tesses.WebServer.Console/Program.cs" Line="23" Column="36" />
<File FileName="Tesses.WebServer/TessesServer.cs" Line="378" Column="42" />
<File FileName="Tesses.WebServer/ServerContext.cs" Line="69" Column="9" />
<File FileName="Tesses.WebServer/TessesServer.cs" Line="436" Column="40" />
<File FileName="Tesses.WebServer/ServerContext.cs" Line="64" Column="14" />
<File FileName="Tesses.WebServer/StatusCodeMap.cs" Line="28" Column="9" />
<File FileName="Tesses.WebServer/SimpleHttpCode.cs" Line="12" Column="83" />
<File FileName="Tesses.WebServer.Console/Server.cs" Line="11" Column="13" />
<File FileName="Tesses.WebServer.Console/packages.config" Line="1" Column="1" />
</Files>
<Pads>
<Pad Id="ProjectPad">
<State name="__root__">
<Node name="Tesses.WebServer" expanded="True">
<Node name="Tesses.WebServer" expanded="True" />
<Node name="Tesses.WebServer.Console" expanded="True">
<Node name="Program.cs" selected="True" />
<Node name="Tesses.WebServer" expanded="True">
<Node name="TessesServer.cs" selected="True" />
</Node>
<Node name="Tesses.WebServer.Console" expanded="True" />
</Node>
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.ItemProperties.Tesses.WebServer.Console PreferredExecutionTarget="MonoDevelop.Default" />
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.DebuggingService.Breakpoints>

View File

@ -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
}
}
}

View File

@ -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("")]

View File

@ -83,3 +83,4 @@ namespace Tesses.WebServer.ConsoleApp
}
}
}

View File

@ -1,55 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Tesses.WebServer.NetStandard\Tesses.WebServer.NetStandard.csproj" />
</ItemGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{3E464D71-CC54-4E71-9C8F-60B0ADF11EC1}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Tesses.WebServer.Console</RootNamespace>
<AssemblyName>Tesses.WebServer.Console</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="MimeTypesMap">
<HintPath>..\packages\MimeTypesMap.1.0.8\lib\net452\MimeTypesMap.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tesses.WebServer\Tesses.WebServer.csproj">
<Project>{24949E8A-6661-4853-B2A2-FC957C1B58C3}</Project>
<Name>Tesses.WebServer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MimeTypesMap" version="1.0.8" targetFramework="net47" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net47" />
</packages>

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Tesses.WebServer</PackageId>
<Author>Mike Nolan</Author>
<Company>Tesses</Company>
<Description>A TCP Listener HTTP(s) Server</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageTags>HTTP, WebServer, Website</PackageTags>
<RepositoryUrl>https://gitlab.tesses.cf/tesses50/tesses.webserver</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MimeTypesMap" Version="1.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>

View File

@ -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)

View File

@ -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

View File

@ -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("")]

View File

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{24949E8A-6661-4853-B2A2-FC957C1B58C3}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Tesses.WebServer</RootNamespace>
<AssemblyName>Tesses.WebServer</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="MimeTypesMap">
<HintPath>..\packages\MimeTypesMap.1.0.8\lib\net452\MimeTypesMap.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="TessesServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerContext.cs" />
<Compile Include="StatusCodeMap.cs" />
<Compile Include="SimpleHttpCode.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MimeTypesMap" version="1.0.8" targetFramework="net47" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net47" />
</packages>