public void Handle_Request(object sender, _socket <HttpListener, HttpListenerContext, long, Exception> .RequestEventArgs <HttpListenerContext> e) { e.Result.Response.StatusCode = 200; e.Result.Response.StatusDescription = "OK"; e.Result.Response.KeepAlive = e.Result.Request.KeepAlive; if (e.Path.EndsWith("/") || e.Path == "/" || e.Path.EndsWith(".html") || e.Path.EndsWith(".htm")) { var response = GenerateSite(e.Result, e.Parameters); e.Result.Response.ContentType = "text/html"; HttpSockets.Request(e.Id).Send(response, e.Result); } else { var bytes = new byte[0]; try { using (var fs = new Filesystem("http_root/")) bytes = fs.Read(e.Path).Result; } catch (Exception) { e.Result.Response.StatusCode = 404; e.Result.Response.StatusDescription = "Not Found!"; } HttpSockets.Request(e.Id).Send(bytes, e.Result); } }
public void Handle_Request(object sender, _socket <HttpListener, HttpListenerContext, long, Exception> .RequestEventArgs <HttpListenerContext> e) { var response = string.Empty; var context = e.Result; // Protect the backend with an username and password. if (!Handle_Auth_Request(context)) { context.Response.ContentType = "text/html"; context.Response.StatusCode = 401; context.Response.StatusDescription = "Not Authenticated!"; HttpSockets.Request(e.Id).Send(response, context); } else { context.Response.ContentType = "application/json"; context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; var resp = ""; if (e.Parameters.ContainsKey("Provider")) { var providers = e.Parameters["Provider"].Split(';'); foreach (var provider in providers) { switch (provider) { case "content": resp = Handle_Provider_Request(Content, "Request", e.Parameters); break; case "user": resp = Handle_Provider_Request(Users, "Request", e.Parameters); break; case "navigation": resp = Handle_Provider_Request(Navigation, "Request", e.Parameters); break; case "news": resp = Handle_Provider_Request(News, "Request", e.Parameters); break; default: break; } } } response = resp; HttpSockets.Request(e.Id).Send(response, context); } }
public void Handle_Error (object sender, _socket <HttpListener, HttpListenerContext, long, Exception> .ErrorEventArgs <Exception> e) => Console.WriteLine("Error: {0}", e.Result);
public void Handle_Response (object sender, _socket <HttpListener, HttpListenerContext, long, Exception> .ResponseEventArgs <long> e) => Console.WriteLine("Sent {0} bytes in response for {1}...", e.Result, e.Path);