public async Task HttpServer() { Mono.Net.HttpListener listener = new Mono.Net.HttpListener(); listener.Prefixes.Add(Statics.Config.IniReadValue("http-server")); listener.Start(); while (true) { Mono.Net.HttpListenerContext client = await listener.GetContextAsync(); if (Statics.RedisDb.Bans.Any(x => x.IpBan == client.Request.UserHostAddress)) { Ban ban = Statics.RedisDb.Bans.First(x => x.IpBan == client.Request.UserHostAddress); if ((DateTime.Now - ban.Begin).Minutes > ban.Minutes) { AcceptHttpClient(client); Statics.RedisDb.Remove(ban); } else { Logger.Log(Logger.LogLevel.General, "Reject ban client from ip {0}", client.Request.UserHostAddress); } } else { AcceptHttpClient(client); } } }
public async void AcceptHttpClient( HttpListenerContext client) { var sRequest = Helpers.GetRequestBody(client.Request); //sRequest = Helpers.GetRequestBody(client.Request); if (sRequest == "") return; var close = false; var guid = ""; var s = AcceptClient(sRequest, client.Request.UserHostAddress, ref close, ref guid); var byteArray = Encoding.UTF8.GetBytes(s); client.Response.ContentType = "application/json"; client.Response.ContentLength64 = byteArray.Length; client.Response.OutputStream.Write(byteArray, 0, byteArray.Length); /* foreach (var b in client.connections) { } */ //client. client.Response.OutputStream.Close(); // if (close) client.Response.Close(); if (close) client.Request.InputStream.Dispose(); }
public DirectoryListing(Internal.Access ac, Mono.Net.HttpListenerContext p, FileInfo fi) { this._ac = ac; this._p = p; _fi = fi; }