yipee head

This commit is contained in:
Siomek101 2025-06-14 23:13:01 +02:00
parent 13f35270f4
commit 96f80773c2
8 changed files with 17 additions and 4 deletions

View File

@ -15,7 +15,8 @@ namespace myownhttp
{ {
undefined = -1, undefined = -1,
GET = 0, GET = 0,
POST = 1 // add more in future POST = 1,
HEAD = 2,// add more in future
} }
public class HTTPReq public class HTTPReq
{ {
@ -40,6 +41,7 @@ namespace myownhttp
var splitfirst = split[0].Split(" "); var splitfirst = split[0].Split(" ");
if (splitfirst[0] == "GET") Method = HTTPMeth.GET; if (splitfirst[0] == "GET") Method = HTTPMeth.GET;
else if (splitfirst[0] == "POST") Method = HTTPMeth.POST; else if (splitfirst[0] == "POST") Method = HTTPMeth.POST;
else if (splitfirst[0] == "HEAD") Method = HTTPMeth.HEAD;
Path = splitfirst[1]; // check if the path Path = splitfirst[1]; // check if the path
HTTPVersion = splitfirst[2]; HTTPVersion = splitfirst[2];
@ -95,7 +97,10 @@ namespace myownhttp
public HTTPRes SetBytes(string str) { contentBytes = Encoding.UTF8.GetBytes(str); return this; } public HTTPRes SetBytes(string str) { contentBytes = Encoding.UTF8.GetBytes(str); return this; }
public string ContentType = GetMimeType("txt"); public string ContentType = GetMimeType("txt");
public bool isHead = false;
string Status = GetStatusFromNum(200); string Status = GetStatusFromNum(200);
DateTime creationDate = DateTime.Now;
public string GetStatus() { return Status; } public string GetStatus() { return Status; }
public HTTPRes SetStatus(int num) { SetStatus(GetStatusFromNum(num)); return this; } public HTTPRes SetStatus(int num) { SetStatus(GetStatusFromNum(num)); return this; }
@ -104,8 +109,15 @@ namespace myownhttp
public byte[] Build() public byte[] Build()
{ {
return Encoding.UTF8.GetBytes( return isHead ?
$"HTTP/1.0 {Status}\r\n" + 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-Type: {ContentType}\n" +
$"Content-Length: {contentBytes.Length}" + $"Content-Length: {contentBytes.Length}" +
$"\n" + $"\n" +
@ -272,6 +284,7 @@ namespace myownhttp
if (req.valid) if (req.valid)
{ {
HTTPRes res = new HTTPRes(); HTTPRes res = new HTTPRes();
res.isHead = req.Method == HTTPMeth.HEAD;
int nextAct = 0; int nextAct = 0;
Action next = () => { }; Action next = () => { };
next = () => next = () =>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("myownhttp")] [assembly: System.Reflection.AssemblyCompanyAttribute("myownhttp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [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.AssemblyProductAttribute("myownhttp")]
[assembly: System.Reflection.AssemblyTitleAttribute("myownhttp")] [assembly: System.Reflection.AssemblyTitleAttribute("myownhttp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

Binary file not shown.

Binary file not shown.