tesses.webserver/Tesses.WebServer.NetStandard/StatusCodeMap.cs

79 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
namespace Tesses.WebServer
{
public class StatusCodeMap
{
public StatusCodeMap()
{
}
public static string GetStatusString(int status_code)
{
string res;
if(_statusCodeMap.Value.TryGetValue(status_code,out res))
{
return res;
}
return "";
}
public static int GetStatusCode(string status)
{
return _statusCodeMap.Value.FirstOrDefault(e=> e.Value== status).Key;
}
private static Lazy<Dictionary<int, string>> _statusCodeMap = new Lazy<Dictionary<int, string>>(() => new Dictionary<int, string>()
{
[202] = "Accepted",
[502] = "Bad Gateway",
[400] = "Bad Request",
[409] = "Conflict",
[100] = "Continue",
[201] = "Created",
[417] = "Expectation Failed",
[403] = "Forbidden",
[302] = "Found",
[504] = "Gateway Timeout",
[410] = "Gone",
[505] = "HTTP Version Not Supported",
[500] = "Internal Server Error",
[411] = "Length Required",
[405] = "Method Not Allowed",
[301] = "Moved Permanently",
[300] = "Multiple Choices",
[204] = "No Content",
[203] = "Non Authoritative Information",
[406] = "Not Acceptable",
[404] = "Not Found",
[501] = "Not Implemented",
[304] = "Not Modified",
[200] = "OK",
[206] = "Partial Content",
[402] = "Payment Required",
[412] = "Precondition Failed",
[407] = "Proxy Authentication Required",
[302] = "Redirect",
[307] = "Redirect Keep Verb",
[303] = "Redirect Method",
[416] = "Requested Range Not Satisfiable",
[413] = "Request Entry Too Large",
[408] = "Request Timeout",
[414] = "Request Uri Too Long",
[205] = "Reset Content",
[503] = "Service Unavailable",
[101] = "Switching Protocols",
[307] = "Temporary Redirect",
[401] = "Unauthorized",
[415] = "Unsupported Media Type",
[306] = "Unused",
[426] = "Upgrade Required",
[305] = "Use Proxy",
[429] = "Too Many Requests"
});
}
}