yipee head
This commit is contained in:
parent
13f35270f4
commit
96f80773c2
19
Program.cs
19
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,8 +97,11 @@ 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; }
|
||||
public HTTPRes SetStatus(string status) { Status = status; 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 = () =>
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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")]
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user