77 {
78
79 var associatedFiles = GetType().GetCustomAttributes<AssociatedFile>();
80 if (associatedFiles.Any())
81 {
82 var file = associatedFiles.Where(a => a.MethodMatches(req.
METHOD) || a.CustomMethodMatches(req.RawMethod.ToUpper()));
83 if (file.Any())
84 {
85 var path = file.First().FilePath;
86 if(!Path.IsPathRooted(path)){
87
88 path = Path.Combine(Directory.GetCurrentDirectory(), path);
89 }
90 if(File.Exists(path)){
92
93 }
94 return;
95 }
96 }
97
99 {
100 case HTTP_METHOD.GET:
101 ProcessGet();
102 break;
103 case HTTP_METHOD.POST:
104 ProcessPost();
105 break;
106 case HTTP_METHOD.PUT:
107 ProcessPut();
108 break;
109 case HTTP_METHOD.DELETE:
110 ProcessDelete();
111 break;
112 case HTTP_METHOD.HEAD:
113 ProcessHead();
114 break;
115 case HTTP_METHOD.PATCH:
116 ProcessPatch();
117 break;
118 case HTTP_METHOD.OPTIONS:
119 ProcessOptions();
120 break;
121 case HTTP_METHOD.TRACE:
122 ProcessTrace();
123 break;
124 case HTTP_METHOD.CONNECT:
125 ProcessConnect();
126 break;
127 default:
128 if (!CustomMethodsMap.Any()) { res.
Send(HTTP_CODES.METHOD_NOT_ALLOWED);
return; };
129 if (CustomMethodsMap.ContainsKey(req.RawMethod.ToUpper()))
130 {
131 Terminal.INFO($"Custom method requested for route '{req.URL}'", true);
132 CustomMethodsMap[req.RawMethod].DynamicInvoke(req, res);
133 return;
134 }
135 if (handlerFallback != null)
136 {
137 handlerFallback.DynamicInvoke();
138 return;
139 }
140 Terminal.ERROR($"Can't process request, unknown HTTP method or malformed request : {req.GetRawRequest}", true);
141 res.
SendCode(HTTP_CODES.METHOD_NOT_ALLOWED);
142 break;
143
144 }
145 }
HTTP_METHOD METHOD
Return the method of the request.
void SendCode(int statusCode)
Send an HTTP Response with no body but with given status code.
void Send(byte[] data, bool disconnect=true)
Send an un modified byte array to to the socket.
void SendFile(string absPath, string? mimeType=null, int statusCode=HTTP_CODES.OK, Dictionary< string, string >? customHeaders=null)
Loads a file from a given path and sends an HTTP Response.