Exemple #1
0
        public static HttpResponce GenerateResponce(HttpRequest req)
        {
            var path = req.GetPath().Split('?')[0];

            if(Program.Cfg.DisabledPaths.Contains(path))
            {
                return new StringResponce("Forbiden");
            }

            var root = "";

            var hst = req.GetHost();
            if (Program.Cfg.VhostTable.ContainsKey(hst))
            {
                root = Program.Cfg.VhostTable[hst];
            }
            else
            {
                root = Program.Cfg.VhostTable.Values.First();
            }

            string file = "";

            if (path == "/")
            {
                //hard coded for now
                if (File.Exists(root.TrimEnd('\\').TrimEnd('/') + path + "index.html"))
                {
                    file = root.TrimEnd('\\').TrimEnd('/') + path + "index.html";
                }
                if (File.Exists(root.TrimEnd('\\').TrimEnd('/') + path + "index.cs"))
                {
                    file = root.TrimEnd('\\').TrimEnd('/') + path + "index.cs";
                }
            }

            if (File.Exists(root.TrimEnd('\\').TrimEnd('/') + path))
            {
                file = root.TrimEnd('\\').TrimEnd('/') + path;
            }

            if(!string.IsNullOrEmpty(file))
            {
                file = Path.GetFullPath(file);
                if(file.StartsWith(Path.GetFullPath(root)))// makes sure user can acces file system with ../
                {
                    if(file.EndsWith(".cs"))
                    {
                        return new WebSharpResponce(file, req);
                    }
                    else
                    {
                        return new FileResponce(file);
                    }
                }
            }

            return new StringResponce("404");
        }
Exemple #2
0
 public WebSharpInterpiter(string src, HttpHeader h, HttpRequest rh)
 {
     Headers.Fields.Clear();
     Raw = src;
     ReqHeaders = rh;
     WriteHeader = (s) => {
         Headers.Fields.Add(new GenericHeader() { Raw = s });
     };
 }
Exemple #3
0
 public WebSharpResponce(string content, HttpRequest r)
 {
     Content = content;
     req = r;
 }