コード例 #1
0
ファイル: Logger.cs プロジェクト: 4eJI0Be4ur/XServer
        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);
        }
コード例 #2
0
ファイル: HttpResponse.cs プロジェクト: 4eJI0Be4ur/XServer
        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");
        }
コード例 #3
0
ファイル: Logger.cs プロジェクト: 4eJI0Be4ur/XServer
        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";
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
ファイル: Controller.cs プロジェクト: 4eJI0Be4ur/XServer
 public virtual int OnConnection(HttpRequest request, HttpResponse response)
 {
     return 200;
 }
コード例 #6
0
        public override int OnConnection(HttpRequest request, HttpResponse response)
        {
            response.SetFile(@"favicon.png");

            return base.OnConnection(request, response);
        }
コード例 #7
0
ファイル: HttpRequest.cs プロジェクト: 4eJI0Be4ur/XServer
        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;
            }
        }
コード例 #8
0
 public override int OnConnection(HttpRequest request, HttpResponse response)
 {
     return 404;
 }
コード例 #9
0
 public override int OnConnection(HttpRequest request, HttpResponse response)
 {
     response.SetBody("Hello World");
     return base.OnConnection(request, response);
 }