private void Handle(object sender, HttpRequestEventArgs e) { string path = e.RequestContext.Request.Url.AbsolutePath; lock (_paths) { HttpPathHandler handler = this[path]; if (handler != null) { CoreManager.ServerCore.ConsoleManager.Debug("Web Admin", "WebAdmin Request [200]: " + path); Task.Factory.StartNew(() => handler(e.RequestContext)); return; } } CoreManager.ServerCore.ConsoleManager.Debug("Web Admin", "WebAdmin Request [404]: " + path); HttpListenerResponse response = e.RequestContext.Response; byte[] buffer = Encoding.UTF8.GetBytes("Not Handled!"); response.StatusCode = (int)HttpStatusCode.NotFound; response.StatusDescription = "Not Found"; response.ContentLength64 = buffer.Length; response.ContentEncoding = Encoding.UTF8; response.OutputStream.Write(buffer, 0, buffer.Length); response.OutputStream.Close(); response.Close(); }
/// <summary> /// Registers a path handler to a path. /// </summary> /// <param name="Path">The path to register to.</param> /// <param name="Handler">The handler for the path.</param> /// <returns>True on success, false on failure (handler already taken).</returns> public bool AddPathHandler(string Path, HttpPathHandler Handler) { lock (this.fPaths) { if (IsPathHandled(Path)) return false; this.fPaths.Add(Path, Handler); CoreManager.GetCore().GetStandardOut().PrintDebug("WebAdmin handler added: " + Path); return true; } }
/// <summary> /// Registers a path handler to a path. /// </summary> /// <param name = "path">The path to register to.</param> /// <param name = "handler">The handler for the path.</param> /// <returns>True on success, false on failure (handler already taken).</returns> public bool AddPathHandler(string path, HttpPathHandler handler) { lock (_paths) { if (IsPathHandled(path)) return false; _paths.Add(path, handler); CoreManager.ServerCore.GetStandardOut().PrintDebug("WebAdmin handler added: " + path); return true; } }
/// <summary> /// Registers a path handler to a path. /// </summary> /// <param name = "path">The path to register to.</param> /// <param name = "handler">The handler for the path.</param> /// <returns>True on success, false on failure (handler already taken).</returns> public bool AddPathHandler(string path, HttpPathHandler handler) { lock (_paths) { if (IsPathHandled(path)) { return(false); } _paths.Add(path, handler); CoreManager.ServerCore.GetStandardOut().PrintDebug("WebAdmin handler added: " + path); return(true); } }