diff --git a/Program.cs b/Program.cs index e9684c1..dfb3824 100644 --- a/Program.cs +++ b/Program.cs @@ -15,7 +15,8 @@ namespace myownhttp { undefined = -1, GET = 0, - POST = 1 // add more in future + POST = 1, + HEAD = 2,// add more in future } public class HTTPReq { @@ -40,6 +41,7 @@ namespace myownhttp var splitfirst = split[0].Split(" "); if (splitfirst[0] == "GET") Method = HTTPMeth.GET; else if (splitfirst[0] == "POST") Method = HTTPMeth.POST; + else if (splitfirst[0] == "HEAD") Method = HTTPMeth.HEAD; Path = splitfirst[1]; // check if the path HTTPVersion = splitfirst[2]; @@ -95,7 +97,10 @@ namespace myownhttp public HTTPRes SetBytes(string str) { contentBytes = Encoding.UTF8.GetBytes(str); return this; } public string ContentType = GetMimeType("txt"); + public bool isHead = false; string Status = GetStatusFromNum(200); + + DateTime creationDate = DateTime.Now; public string GetStatus() { return Status; } public HTTPRes SetStatus(int num) { SetStatus(GetStatusFromNum(num)); return this; } @@ -104,8 +109,15 @@ namespace myownhttp public byte[] Build() { - return Encoding.UTF8.GetBytes( - $"HTTP/1.0 {Status}\r\n" + + return isHead ? + Encoding.UTF8.GetBytes( + $"HTTP/1.1 {Status}\r\n" + + $"Date: {creationDate.ToUniversalTime()}\r\n"+ + $"Content-Length: {contentBytes.Length}\r\n" + + $"Content-Type: {ContentType}\r\n" + ) : + Encoding.UTF8.GetBytes( + $"HTTP/1.1 {Status}\r\n" + $"Content-Type: {ContentType}\n" + $"Content-Length: {contentBytes.Length}" + $"\n" + @@ -272,6 +284,7 @@ namespace myownhttp if (req.valid) { HTTPRes res = new HTTPRes(); + res.isHead = req.Method == HTTPMeth.HEAD; int nextAct = 0; Action next = () => { }; next = () => diff --git a/bin/Debug/net9.0/myownhttp.dll b/bin/Debug/net9.0/myownhttp.dll index 1697a44..6ca3fa3 100644 Binary files a/bin/Debug/net9.0/myownhttp.dll and b/bin/Debug/net9.0/myownhttp.dll differ diff --git a/bin/Debug/net9.0/myownhttp.exe b/bin/Debug/net9.0/myownhttp.exe index a0fe5bf..a21a6d7 100644 Binary files a/bin/Debug/net9.0/myownhttp.exe and b/bin/Debug/net9.0/myownhttp.exe differ diff --git a/obj/Debug/net9.0/apphost.exe b/obj/Debug/net9.0/apphost.exe index a0fe5bf..a21a6d7 100644 Binary files a/obj/Debug/net9.0/apphost.exe and b/obj/Debug/net9.0/apphost.exe differ diff --git a/obj/Debug/net9.0/myownhttp.AssemblyInfo.cs b/obj/Debug/net9.0/myownhttp.AssemblyInfo.cs index d2349a4..a891cae 100644 --- a/obj/Debug/net9.0/myownhttp.AssemblyInfo.cs +++ b/obj/Debug/net9.0/myownhttp.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("myownhttp")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ec256f2f5303de6a08e5be2277a2dfff55c836b9")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+13f35270f4504484290b43ad3035eef0c99129c6")] [assembly: System.Reflection.AssemblyProductAttribute("myownhttp")] [assembly: System.Reflection.AssemblyTitleAttribute("myownhttp")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net9.0/myownhttp.dll b/obj/Debug/net9.0/myownhttp.dll index 1697a44..6ca3fa3 100644 Binary files a/obj/Debug/net9.0/myownhttp.dll and b/obj/Debug/net9.0/myownhttp.dll differ diff --git a/obj/Debug/net9.0/ref/myownhttp.dll b/obj/Debug/net9.0/ref/myownhttp.dll index 3586ad3..4b5b373 100644 Binary files a/obj/Debug/net9.0/ref/myownhttp.dll and b/obj/Debug/net9.0/ref/myownhttp.dll differ diff --git a/obj/Debug/net9.0/refint/myownhttp.dll b/obj/Debug/net9.0/refint/myownhttp.dll index 3586ad3..4b5b373 100644 Binary files a/obj/Debug/net9.0/refint/myownhttp.dll and b/obj/Debug/net9.0/refint/myownhttp.dll differ