diff --git a/src/Server/.idea/.idea.REST API/.idea/workspace.xml b/src/Server/.idea/.idea.REST API/.idea/workspace.xml index b19f146..4764cc5 100644 --- a/src/Server/.idea/.idea.REST API/.idea/workspace.xml +++ b/src/Server/.idea/.idea.REST API/.idea/workspace.xml @@ -8,203 +8,29 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - + - + + + + + diff --git a/src/Server/Console/bin/Debug/net8.0/Console.dll b/src/Server/Console/bin/Debug/net8.0/Console.dll index 13dacba..a1cb4cd 100644 Binary files a/src/Server/Console/bin/Debug/net8.0/Console.dll and b/src/Server/Console/bin/Debug/net8.0/Console.dll differ diff --git a/src/Server/Console/bin/Debug/net8.0/Console.exe b/src/Server/Console/bin/Debug/net8.0/Console.exe index 9e338d7..f4528cf 100644 Binary files a/src/Server/Console/bin/Debug/net8.0/Console.exe and b/src/Server/Console/bin/Debug/net8.0/Console.exe differ diff --git a/src/Server/Console/bin/Debug/net8.0/Console.pdb b/src/Server/Console/bin/Debug/net8.0/Console.pdb index 4691a59..c280e50 100644 Binary files a/src/Server/Console/bin/Debug/net8.0/Console.pdb and b/src/Server/Console/bin/Debug/net8.0/Console.pdb differ diff --git a/src/Server/Console/bin/Debug/net8.0/LibHttp.dll b/src/Server/Console/bin/Debug/net8.0/LibHttp.dll index 827b85f..db1698f 100644 Binary files a/src/Server/Console/bin/Debug/net8.0/LibHttp.dll and b/src/Server/Console/bin/Debug/net8.0/LibHttp.dll differ diff --git a/src/Server/Console/bin/Debug/net8.0/LibHttp.pdb b/src/Server/Console/bin/Debug/net8.0/LibHttp.pdb index da5b50e..6af2df0 100644 Binary files a/src/Server/Console/bin/Debug/net8.0/LibHttp.pdb and b/src/Server/Console/bin/Debug/net8.0/LibHttp.pdb differ diff --git a/src/Server/Console/bin/Debug/net8.0/LibServer.dll b/src/Server/Console/bin/Debug/net8.0/LibServer.dll index b1fac83..b061741 100644 Binary files a/src/Server/Console/bin/Debug/net8.0/LibServer.dll and b/src/Server/Console/bin/Debug/net8.0/LibServer.dll differ diff --git a/src/Server/Console/bin/Debug/net8.0/LibServer.pdb b/src/Server/Console/bin/Debug/net8.0/LibServer.pdb index 43e54de..01ecc06 100644 Binary files a/src/Server/Console/bin/Debug/net8.0/LibServer.pdb and b/src/Server/Console/bin/Debug/net8.0/LibServer.pdb differ diff --git a/src/Server/LibHttp/MimeTypes.cs b/src/Server/LibHttp/MimeTypes.cs index a48e84a..08f2024 100644 --- a/src/Server/LibHttp/MimeTypes.cs +++ b/src/Server/LibHttp/MimeTypes.cs @@ -6,6 +6,50 @@ public enum Mime { Text }; +public enum Method { + Get, + Post, + Put, + Delete, + Patch, + Head, + Options, + Connect, + Trace +}; + +public static class MethodClass { + public static string MethodToString(Method method) { + return method switch { + Method.Get => "GET", + Method.Post => "POST", + Method.Put => "PUT", + Method.Delete => "DELETE", + Method.Patch => "PATCH", + Method.Head => "HEAD", + Method.Options => "OPTIONS", + Method.Connect => "CONNECT", + Method.Trace => "TRACE", + _ => "GET" + }; + } + + public static Method StringToMethod(string method) { + return method switch { + "GET" => Method.Get, + "POST" => Method.Post, + "PUT" => Method.Put, + "DELETE" => Method.Delete, + "PATCH" => Method.Patch, + "HEAD" => Method.Head, + "OPTIONS" => Method.Options, + "CONNECT" => Method.Connect, + "TRACE" => Method.Trace, + _ => Method.Get + }; + } +} + public static class MimeTypes { public static string MimeToHeader(Mime mime) { return mime switch { diff --git a/src/Server/LibHttp/Request.cs b/src/Server/LibHttp/Request.cs index 313e2b0..2cb3c20 100644 --- a/src/Server/LibHttp/Request.cs +++ b/src/Server/LibHttp/Request.cs @@ -4,9 +4,10 @@ public class HtmlRequest { private const string LogPrefix = "\u001b[47m[ WWW ]\u001b[0m"; public string? Route; - private string? _httpVersion, _host, _body, _header, _method; + private string? _httpVersion, _host, _body, _header; + private Method? _method; - public string? Method => _method; + public Method? Method => _method; public string? Body => _body; public int Parse(string raw) { @@ -25,7 +26,7 @@ public class HtmlRequest { if (i == 0) { if (!parts[0].Contains("HTTP")) return -1; var first = parts[0].Split(" "); - _method = first[0].ToUpper(); + _method = MethodClass.StringToMethod(first[0].ToUpper()); Route = first[1]; _httpVersion = first[2].Split("/")[1]; } else { diff --git a/src/Server/LibHttp/bin/Debug/net8.0/LibHttp.dll b/src/Server/LibHttp/bin/Debug/net8.0/LibHttp.dll index 827b85f..a450762 100644 Binary files a/src/Server/LibHttp/bin/Debug/net8.0/LibHttp.dll and b/src/Server/LibHttp/bin/Debug/net8.0/LibHttp.dll differ diff --git a/src/Server/LibHttp/bin/Debug/net8.0/LibHttp.pdb b/src/Server/LibHttp/bin/Debug/net8.0/LibHttp.pdb index da5b50e..001d38c 100644 Binary files a/src/Server/LibHttp/bin/Debug/net8.0/LibHttp.pdb and b/src/Server/LibHttp/bin/Debug/net8.0/LibHttp.pdb differ diff --git a/src/Server/LibServer/Router/Router.cs b/src/Server/LibServer/Router/Router.cs index fc73aec..a411e56 100644 --- a/src/Server/LibServer/Router/Router.cs +++ b/src/Server/LibServer/Router/Router.cs @@ -10,13 +10,13 @@ public class Router(Dictionary routes) { foreach (var route in Routes) { if (request.Route == route.Key) { return request.Method switch { - "GET" => route.Value.Get(request), - "POST" => route.Value.Post(request), - "PUT" => route.Value.Put(request), - "PATCH" => route.Value.Patch(request), - "DELETE" => route.Value.Delete(request), - "HEAD" => route.Value.Head(request), - "OPTIONS" => route.Value.Options(request), + Method.Get => route.Value.Get(request), + Method.Post => route.Value.Post(request), + Method.Put => route.Value.Put(request), + Method.Patch => route.Value.Patch(request), + Method.Delete => route.Value.Delete(request), + Method.Head => route.Value.Head(request), + Method.Options => route.Value.Options(request), _ => route.Value.MethodNotAllowed() }; } diff --git a/src/Server/LibServer/bin/Debug/net8.0/LibHttp.dll b/src/Server/LibServer/bin/Debug/net8.0/LibHttp.dll index 827b85f..db1698f 100644 Binary files a/src/Server/LibServer/bin/Debug/net8.0/LibHttp.dll and b/src/Server/LibServer/bin/Debug/net8.0/LibHttp.dll differ diff --git a/src/Server/LibServer/bin/Debug/net8.0/LibHttp.pdb b/src/Server/LibServer/bin/Debug/net8.0/LibHttp.pdb index da5b50e..6af2df0 100644 Binary files a/src/Server/LibServer/bin/Debug/net8.0/LibHttp.pdb and b/src/Server/LibServer/bin/Debug/net8.0/LibHttp.pdb differ diff --git a/src/Server/LibServer/bin/Debug/net8.0/LibServer.dll b/src/Server/LibServer/bin/Debug/net8.0/LibServer.dll index b1fac83..b061741 100644 Binary files a/src/Server/LibServer/bin/Debug/net8.0/LibServer.dll and b/src/Server/LibServer/bin/Debug/net8.0/LibServer.dll differ diff --git a/src/Server/LibServer/bin/Debug/net8.0/LibServer.pdb b/src/Server/LibServer/bin/Debug/net8.0/LibServer.pdb index 43e54de..01ecc06 100644 Binary files a/src/Server/LibServer/bin/Debug/net8.0/LibServer.pdb and b/src/Server/LibServer/bin/Debug/net8.0/LibServer.pdb differ diff --git a/src/Server/REST API.sln.DotSettings.user b/src/Server/REST API.sln.DotSettings.user index 834d0a1..e414376 100644 --- a/src/Server/REST API.sln.DotSettings.user +++ b/src/Server/REST API.sln.DotSettings.user @@ -1,5 +1,11 @@  INFO <SessionState ContinuousTestingMode="0" IsActive="True" Name="ParseJsonToAnonymousObject" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <ProjectFile>56E0FEEA-8155-4979-8E90-EF2F3DA4B9E4/f:LibParse.cs</ProjectFile> + <Or> + <ProjectFile>56E0FEEA-8155-4979-8E90-EF2F3DA4B9E4/f:LibParse.cs</ProjectFile> + <TestAncestor> + <TestId>NUnit3x::56E0FEEA-8155-4979-8E90-EF2F3DA4B9E4::net8.0::Tests.LibHttpTests.TestGet</TestId> + <TestId>NUnit3x::56E0FEEA-8155-4979-8E90-EF2F3DA4B9E4::net8.0::Tests.LibHttpTests.TestSend</TestId> + </TestAncestor> + </Or> </SessionState> \ No newline at end of file diff --git a/src/Server/Tests/LibHttp.cs b/src/Server/Tests/LibHttp.cs new file mode 100644 index 0000000..b33abfb --- /dev/null +++ b/src/Server/Tests/LibHttp.cs @@ -0,0 +1,28 @@ +namespace Tests; +using LibHttp; + +public class LibHttpTests { + private static readonly string Body = "Hello, World!"; + private static readonly Method Method = Method.Get; + + [Test] + public void TestGet() { + const string message = "GET /tests HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\nHello, World!"; + var request = new HtmlRequest(); + request.Parse(message); + Assert.Multiple(() => { + Assert.That(Body, Is.EqualTo(request.Body)); + Assert.That(Method, Is.EqualTo(request.Method)); + }); + } + + [Test] + public void TestSend() { + var response = new HtmlResponse("Hello, World!"); + + Assert.Multiple(() => { + Assert.That(Body, Is.EqualTo(response.Body)); + Assert.That(response.Headers, Has.Count.EqualTo(1)); + }); + } +} diff --git a/src/Server/Tests/Tests.csproj b/src/Server/Tests/Tests.csproj index bf52604..fb6fce4 100644 --- a/src/Server/Tests/Tests.csproj +++ b/src/Server/Tests/Tests.csproj @@ -18,6 +18,7 @@ + diff --git a/src/Server/Tests/bin/Debug/net8.0/CoverletSourceRootsMapping_Tests b/src/Server/Tests/bin/Debug/net8.0/CoverletSourceRootsMapping_Tests index 9a17cb5..6b16127 100644 Binary files a/src/Server/Tests/bin/Debug/net8.0/CoverletSourceRootsMapping_Tests and b/src/Server/Tests/bin/Debug/net8.0/CoverletSourceRootsMapping_Tests differ diff --git a/src/Server/Tests/bin/Debug/net8.0/LibHttp.dll b/src/Server/Tests/bin/Debug/net8.0/LibHttp.dll new file mode 100644 index 0000000..a450762 Binary files /dev/null and b/src/Server/Tests/bin/Debug/net8.0/LibHttp.dll differ diff --git a/src/Server/Tests/bin/Debug/net8.0/LibHttp.pdb b/src/Server/Tests/bin/Debug/net8.0/LibHttp.pdb new file mode 100644 index 0000000..001d38c Binary files /dev/null and b/src/Server/Tests/bin/Debug/net8.0/LibHttp.pdb differ diff --git a/src/Server/Tests/bin/Debug/net8.0/Tests.deps.json b/src/Server/Tests/bin/Debug/net8.0/Tests.deps.json index e16743a..a8660f6 100644 --- a/src/Server/Tests/bin/Debug/net8.0/Tests.deps.json +++ b/src/Server/Tests/bin/Debug/net8.0/Tests.deps.json @@ -8,6 +8,7 @@ ".NETCoreApp,Version=v8.0": { "Tests/1.0.0": { "dependencies": { + "LibHttp": "1.0.0", "LibParse": "1.0.0", "Microsoft.NET.Test.Sdk": "17.6.0", "NUnit": "3.13.3", @@ -317,6 +318,11 @@ "NUnit.Analyzers/3.6.1": {}, "NUnit3TestAdapter/4.2.1": {}, "System.Reflection.Metadata/1.6.0": {}, + "LibHttp/1.0.0": { + "runtime": { + "LibHttp.dll": {} + } + }, "LibParse/1.0.0": { "runtime": { "LibParse.dll": {} @@ -421,6 +427,11 @@ "path": "system.reflection.metadata/1.6.0", "hashPath": "system.reflection.metadata.1.6.0.nupkg.sha512" }, + "LibHttp/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + }, "LibParse/1.0.0": { "type": "project", "serviceable": false, diff --git a/src/Server/Tests/bin/Debug/net8.0/Tests.dll b/src/Server/Tests/bin/Debug/net8.0/Tests.dll index 6ee05de..90b79cb 100644 Binary files a/src/Server/Tests/bin/Debug/net8.0/Tests.dll and b/src/Server/Tests/bin/Debug/net8.0/Tests.dll differ diff --git a/src/Server/Tests/bin/Debug/net8.0/Tests.pdb b/src/Server/Tests/bin/Debug/net8.0/Tests.pdb index 37c498f..3bae20b 100644 Binary files a/src/Server/Tests/bin/Debug/net8.0/Tests.pdb and b/src/Server/Tests/bin/Debug/net8.0/Tests.pdb differ