public static void LogWarning(string msg, HttpRequest request = null) { string date = DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss GMT+3"); string line = "[" + date + "]" + "[warning] [" + (request != null ? "client " + request.RemoteIp + "] " : "client unknown] ") + msg; WriteLine(line); }
public HttpResponse(HttpRequest request) { this.Request = request; this.stream = request.Stream; this.Headers = new Dictionary<string, string>(); this.RespCode = "UNKNOWN"; Headers.Add("Content-Type", "text/html"); }
public static void Log(string msg, HttpRequest request = null) { string date = DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss GMT+3"); string line = "[" + date + "]" + "[notice] [" + (request != null ? "client " + request.RemoteIp + "] " : "client unknown] ") + msg; WriteLine(line); //"[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /export/home/live/ap/htdocs/test"; }
public override void OnConnection(XServer.HttpRequest request, XServer.HttpResponse response) { var contents = _sfc.ReadFile("index.html"); if (contents != null) { response.SetBody(contents); } else { response.SetCode(404); } }
public virtual int OnConnection(HttpRequest request, HttpResponse response) { return 200; }
public override int OnConnection(HttpRequest request, HttpResponse response) { response.SetFile(@"favicon.png"); return base.OnConnection(request, response); }
public static HttpRequest Parse(Socket socket,NetworkStream stream) { try { HttpRequest request = new HttpRequest(); request.Socket = socket; request.RemoteIp = request.Socket.RemoteEndPoint.ToString(); request.Stream = stream; StreamReader sReader = new StreamReader(stream); bool read = true; Dictionary<string, string> headers = new Dictionary<string, string>(); string head = sReader.ReadLine(); if (head == null) { return null; } //Console.WriteLine(head); //Logger.Log(head); string[] hS = head.Split(' '); switch (hS[0]) { case "GET": request.Method = Methods.GET; break; default: request.Method = Methods.GET; break; } Uri ur = new Uri("http://localhost" + hS[1]); request.QueryString = new QueryString(ur.Query); //Console.WriteLine("URI: "+ur.LocalPath); request.Url = ur; while (read) { string line = sReader.ReadLine(); //Console.WriteLine(line); //Logger.Log(line); if (line == "") break; string[] spl = line.Split(new string[] { ": " }, StringSplitOptions.None); if (spl.Length == 1) spl = line.Split(new string[] { ":" }, StringSplitOptions.None); headers.Add(spl[0], spl[1]); } request.Headers = headers; return request; } catch (Exception ex) { Logger.LogError("Error parsing package \n"+ex.Message+" \n "+ex.StackTrace); return null; } }
public override int OnConnection(HttpRequest request, HttpResponse response) { return 404; }
public override int OnConnection(HttpRequest request, HttpResponse response) { response.SetBody("Hello World"); return base.OnConnection(request, response); }