-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c29143c
commit e660fc0
Showing
8 changed files
with
208 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,4 +362,5 @@ MigrationBackup/ | |
# Fody - auto-generated XML schema | ||
FodyWeavers.xsd | ||
|
||
.env.* | ||
.env.* | ||
.lh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CSharpOpenBMCLAPI.Modules.WebServer | ||
{ | ||
public class Header | ||
{ | ||
Dictionary<string, string> tables; | ||
public Header(Dictionary<string, string> tables) { | ||
this.tables = tables; | ||
} | ||
public Header() | ||
{ | ||
this.tables = new Dictionary<string, string>(); | ||
} | ||
public static Header fromBytes(byte[][] headers) | ||
{ | ||
Dictionary<string, string> tables = new Dictionary<string, string>(); | ||
foreach (var header in headers) | ||
{ | ||
var h = WebUtils.SplitBytes(header, WebUtils.encode(": ").ToArray(), 1).ToArray(); | ||
if (h.Length < 1) | ||
{ | ||
continue; | ||
} | ||
tables.TryAdd(WebUtils.decode(h[0]), WebUtils.decode(h[1])); | ||
} | ||
return new Header(tables); | ||
} | ||
public Object get(string key, Object def) | ||
{ | ||
return tables.ContainsKey(key) ? tables[key] : def; | ||
} | ||
public void set(string key, Object value) | ||
{ | ||
if (value == null) | ||
{ | ||
if (tables.ContainsKey(key)) tables.Remove(key); | ||
return; | ||
} | ||
tables.TryAdd(key, value + ""); | ||
} | ||
public bool ContainsKey(string key) { | ||
return tables.ContainsKey(key); | ||
} | ||
public string ToString() | ||
Check warning on line 49 in CSharp-OpenBMCLAPI/Modules/WebServer/Header.cs GitHub Actions / build (Release)
Check warning on line 49 in CSharp-OpenBMCLAPI/Modules/WebServer/Header.cs GitHub Actions / build (Release)
|
||
{ | ||
string header = ""; | ||
foreach (var key in tables.Keys) | ||
{ | ||
header += key + ": " + tables[key] + "\r\n"; | ||
} | ||
return header; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CSharpOpenBMCLAPI.Modules.WebServer | ||
{ | ||
public class Response | ||
{ | ||
int status_code = 200; | ||
Header header = new Header(); | ||
Stream stream = new MemoryStream(); | ||
public async Task call(Client client, Request request) | ||
{ | ||
header.set("Content-Length", stream.Length); | ||
header.set("Server", "CSharp-SaltWood"); | ||
string responseHeader = "HTTP/1.1 " + status_code + " " + GetStatusMsg(status_code) + "\r\n" + header.ToString() + "\r\n"; | ||
await client.Write(WebUtils.encode(responseHeader)); | ||
} | ||
public static Dictionary<int, string> STATUS_CODES = new Dictionary<int, string> | ||
{ | ||
{ 100, "Continue" }, | ||
{ 101, "Switching Protocols" }, | ||
{ 200, "OK" }, | ||
{ 201, "Created" }, | ||
{ 202, "Accepted" }, | ||
{ 203, "Non-Authoritative Information" }, | ||
{ 204, "No Content" }, | ||
{ 205, "Reset Content" }, | ||
{ 206, "Partial Content" }, | ||
{ 300, "Multiple Choices" }, | ||
{ 301, "Moved Pemanently" }, | ||
{ 302, "Found" }, | ||
{ 303, "See Other" }, | ||
{ 304, "Not Modified" }, | ||
{ 305, "Use Proxy" }, | ||
{ 306, "Unused" }, | ||
{ 307, "Temporary Redirect" }, | ||
{ 400, "Bad Request" }, | ||
{ 401, "Unauthorized" }, | ||
{ 402, "Payment Required" }, | ||
{ 403, "Forbidden" }, | ||
{ 404, "Not Found" }, | ||
{ 405, "Method Not Allowed" }, | ||
{ 406, "Not Acceptable" }, | ||
{ 407, "Proxy Authentication Required" }, | ||
{ 408, "Request Time-out" }, | ||
{ 409, "Conflict" }, | ||
{ 410, "Gone" }, | ||
{ 411, "Length Required" }, | ||
{ 412, "Precondition Failed" }, | ||
{ 413, "Request Entity Too Large" }, | ||
{ 414, "Request-URI Too Large" }, | ||
{ 415, "Unsupported Media Type" }, | ||
{ 416, "Requested range not satisfiable" }, | ||
{ 417, "Expectation Failed" }, | ||
{ 418, "I'm a teapot" }, | ||
{ 421, "Misdirected Request" }, | ||
{ 422, "Unprocessable Entity" }, | ||
{ 423, "Locked" }, | ||
{ 424, "Failed Dependency" }, | ||
{ 425, "Too Early" }, | ||
{ 426, "Upgrade Required" }, | ||
{ 428, "Precondition Required" }, | ||
{ 429, "Too Many Requests" }, | ||
{ 431, "Request Header Fields Too Large" }, | ||
{ 451, "Unavailable For Legal Reasons" }, | ||
{ 500, "Internal Server Eror" }, | ||
{ 501, "Not Implemented" }, | ||
{ 502, "Bad Gateway" }, | ||
{ 503, "Service Unavailable" }, | ||
{ 504, "Gateway Time-out" }, | ||
{ 505, "HTTP Version not supported" }, | ||
}; | ||
public static string GetStatusMsg(int status) | ||
{ | ||
return STATUS_CODES.ContainsKey(status) ? STATUS_CODES[status] : STATUS_CODES[int.Parse((status / 100) + "") * 100]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters