Beispiel #1
0
        public static PanResponse ReturnHtml(string path, Encoding contentEncoding, List <PanCookie> cookies = null) // Return Html page
        {
            string html = File.ReadAllText(path);

            return(PanResponse.ReturnContent(html, contentEncoding, cookies));
        }
Beispiel #2
0
 public static PanResponse ReturnEmtry(List <PanCookie> cookies = null)
 {
     return(PanResponse.ReturnContent("", cookies));
 }
Beispiel #3
0
 public static PanResponse ReturnContent(string content, List <PanCookie> cookies = null) //Return string (content)
 {
     return(PanResponse.ReturnContent(content, Encoding.UTF8, cookies));
 }
Beispiel #4
0
        static public PanResponse OnRequest(PanRequest request)
        {
            var cookies = new List <PanCookie>();

            Console.WriteLine(request.Url + " " + request.IsLocal.ToString() + " " + request.UserIP);
            if (request.Address.Length < 1)
            {
                return(PanResponse.ReturnContent("Emtry page", Encoding.UTF8));
            }
            else
            {
                switch (request.Address[0])
                {
                case "favicon.ico": return(PanResponse.ReturnFile(@"E:\PROJECTS\PanWebsite\Website2\favicon.ico", Encoding.UTF8)); break;

                case "content": return(PanResponse.ReturnContent("Content", Encoding.UTF8)); break;

                case "html": return(PanResponse.ReturnHtml(@"E:\PROJECTS\PanWebsite\Website2\index.html", Encoding.UTF8)); break;

                case "code": return(PanResponse.ReturnCode(500)); break;

                case "file": return(PanResponse.ReturnFile(@"E:\PROJECTS\PanWebsite\Website2\image.jpg", Encoding.UTF8)); break;

                case "json": return(PanResponse.ReturnJson(new { a = 5, s = "fff", b = true })); break;

                case "upload":
                    if (request.Address.Length == 1)
                    {
                        return(PanResponse.ReturnHtml(@"E:\PROJECTS\PanWebsite\Website2\upload.html", Encoding.UTF8)); break;
                    }
                    else if (request.Address[1] == "api")
                    {
                        if (request.HasEntityBody)
                        {
                            var d = request.MutlipartFormData;
                            foreach (var item in d)
                            {
                                if (item.Filename != "")
                                {
                                    FileStream fs = File.Open(Path.Combine(@"E:\PROJECTS\PanWebsite\Website2\downloads", item.Filename), FileMode.Create, FileAccess.ReadWrite);
                                    item.Data.Position = 0;
                                    fs.Position        = 0;
                                    item.Data.CopyTo(fs);
                                    fs.Close();
                                    fs.Dispose();
                                }
                            }
                            return(PanResponse.ReturnCode(200));
                        }
                        else
                        {
                            return(PanResponse.ReturnCode(500));
                        }
                    }
                    else
                    {
                        return(PanResponse.ReturnCode(500)); break;
                    }
                    break;

                default: return(PanResponse.ReturnCode(404)); break;
                }
            }
        }