Пример #1
0
        public void Test_21_Cookies()
        {
            server.Register("/test21_1.txt", (req, resp) =>
            {
                resp.SetCookie(new Cookie("word1", "hej", "localhost", "/"));
                resp.SetCookie(new Cookie("word2", "på", "localhost", "/"));
                resp.SetCookie(new Cookie("word3", "dej", "localhost", "/"));

                resp.Return("hejsan");
            });

            server.Register("/test21_2.txt", (req, resp) =>
            {
                resp.Return(req.Header.Cookie["word1"] + " " + req.Header.Cookie["word2"] + " " + req.Header.Cookie["word3"]);
            });

            using (CookieWebClient Client = new CookieWebClient())
            {
                byte[] Data = Client.DownloadData("http://localhost:8080/test21_1.txt");
                string s    = Encoding.UTF8.GetString(Data);
                Assert.AreEqual("hejsan", s);

                Data = Client.DownloadData("http://localhost:8080/test21_2.txt");
                s    = Encoding.UTF8.GetString(Data);
                Assert.AreEqual("hej på dej", s);
            }
        }
Пример #2
0
        public void Test_26_NotAcceptable()
        {
            server.Register(new HttpFolderResource("/Test26", "Data", false, false, true, false));

            using (CookieWebClient Client = new CookieWebClient())
            {
                Client.Accept = "text/x-test4";
                byte[] Data = Client.DownloadData("http://localhost:8080/Test26/Text.txt");
            }
        }
Пример #3
0
        public void Test_10_FolderResource_PUT_File_NotAllowed()
        {
            server.Register(new HttpFolderResource("/Test10", "Data", false, false, true, false));

            using (CookieWebClient Client = new CookieWebClient())
            {
                Encoding Utf8 = new UTF8Encoding(true);
                byte[]   Data = Client.UploadData("http://localhost:8080/Test10/string.txt", "PUT", Utf8.GetBytes(new string('Ω', 100000)));
            }
        }
Пример #4
0
        public void Test_01_GET_HTTP_ContentLength()
        {
            server.Register("/test01.txt", (req, resp) => resp.Return("hej på dej"));

            using (CookieWebClient Client = new CookieWebClient())
            {
                byte[] Data = Client.DownloadData("http://localhost:8080/test01.txt");
                string s    = Encoding.UTF8.GetString(Data);
                Assert.AreEqual("hej på dej", s);
            }
        }
Пример #5
0
        public void Test_22_Conditional_GET_IfModifiedSince_1()
        {
            DateTime LastModified = File.GetLastWriteTime("Data\\BarnSwallowIsolated-300px.png");

            server.Register(new HttpFolderResource("/Test22", "Data", false, false, true, false));

            using (CookieWebClient Client = new CookieWebClient())
            {
                Client.IfModifiedSince = LastModified.AddMinutes(1);
                byte[] Data = Client.DownloadData("http://localhost:8080/Test22/BarnSwallowIsolated-300px.png");
            }
        }
Пример #6
0
        public void Test_14_FolderResource_DELETE_Folder()
        {
            server.Register(new HttpFolderResource("/Test14", "Data", true, true, true, false));

            using (CookieWebClient Client = new CookieWebClient())
            {
                Encoding Utf8 = new UTF8Encoding(true);
                Client.UploadData("http://localhost:8080/Test14/Folder/string.txt", "PUT", Utf8.GetBytes(new string('Ω', 100000)));

                Client.UploadData("http://localhost:8080/Test14/Folder", "DELETE", new byte[0]);
            }
        }
Пример #7
0
        public void Test_08_FolderResource_GET()
        {
            server.Register(new HttpFolderResource("/Test08", "Data", false, false, true, false));

            using (CookieWebClient Client = new CookieWebClient())
            {
                byte[]   Data = Client.DownloadData("http://localhost:8080/Test08/BarnSwallowIsolated-300px.png");
                SKBitmap Bmp  = SKBitmap.Decode(Data);
                Assert.AreEqual(300, Bmp.Width);
                Assert.AreEqual(264, Bmp.Height);
            }
        }
Пример #8
0
        public void Test_07_EmbeddedResource()
        {
            server.Register(new HttpEmbeddedResource("/test07.png", "Waher.Networking.HTTP.Test.Data.Frog-300px.png", typeof(HttpServerTests).Assembly));

            using (CookieWebClient Client = new CookieWebClient())
            {
                byte[]   Data = Client.DownloadData("http://localhost:8080/test07.png");
                SKBitmap Bmp  = SKBitmap.Decode(Data);
                Assert.AreEqual(300, Bmp.Width);
                Assert.AreEqual(184, Bmp.Height);
            }
        }
Пример #9
0
        public void Test_06_Authentication_Digest()
        {
            server.Register("/test06.txt", (req, resp) => resp.Return("hej på dej"), new DigestAuthentication("Test06", this));

            using (CookieWebClient Client = new CookieWebClient())
            {
                Client.Credentials = new NetworkCredential("User", "Password");
                byte[] Data = Client.DownloadData("http://localhost:8080/test06.txt");
                string s    = Encoding.UTF8.GetString(Data);
                Assert.AreEqual("hej på dej", s);
            }
        }
Пример #10
0
        public void Test_25_Conditional_PUT_IfUnmodifiedSince_2()
        {
            DateTime LastModified = File.GetLastWriteTime("Data\\Temp.txt");

            server.Register(new HttpFolderResource("/Test25", "Data", true, false, true, false));

            using (CookieWebClient Client = new CookieWebClient())
            {
                Encoding Utf8 = new UTF8Encoding(true);
                string   s1   = new string('Ω', 100000);
                Client.IfUnmodifiedSince = LastModified.AddMinutes(1);
                Client.UploadData("http://localhost:8080/Test25/Temp.txt", "PUT", Utf8.GetBytes(s1));
            }
        }
Пример #11
0
        public void Test_23_Conditional_GET_IfModifiedSince_2()
        {
            DateTime LastModified = File.GetLastWriteTime("Data\\BarnSwallowIsolated-300px.png");

            server.Register(new HttpFolderResource("/Test23", "Data", false, false, true, false));

            using (CookieWebClient Client = new CookieWebClient())
            {
                Client.IfModifiedSince = LastModified.AddMinutes(-1);
                byte[]   Data = Client.DownloadData("http://localhost:8080/Test23/BarnSwallowIsolated-300px.png");
                SKBitmap Bmp  = SKBitmap.Decode(Data);
                Assert.AreEqual(300, Bmp.Width);
                Assert.AreEqual(264, Bmp.Height);
            }
        }
Пример #12
0
        public void Test_03_GET_HTTP_Encoding()
        {
            server.Register("/test03.png", (req, resp) =>
            {
                resp.Return(new SKBitmap(320, 200));
            });

            using (CookieWebClient Client = new CookieWebClient())
            {
                byte[]   Data = Client.DownloadData("http://localhost:8080/test03.png");
                SKBitmap Bmp  = SKBitmap.Decode(Data);
                Assert.AreEqual(320, Bmp.Width);
                Assert.AreEqual(200, Bmp.Height);
            }
        }
Пример #13
0
        public void Test_13_FolderResource_PUT_CreateFolder()
        {
            server.Register(new HttpFolderResource("/Test13", "Data", true, false, true, false));

            using (CookieWebClient Client = new CookieWebClient())
            {
                Encoding Utf8 = new UTF8Encoding(true);
                string   s1   = new string('Ω', 100000);
                Client.UploadData("http://localhost:8080/Test13/Folder/string.txt", "PUT", Utf8.GetBytes(s1));

                byte[] Data = Client.DownloadData("http://localhost:8080/Test13/Folder/string.txt");
                string s2   = Utf8.GetString(Data);

                Assert.AreEqual(s1, s2);
            }
        }
Пример #14
0
        public void Test_19_PUT_Range()
        {
            server.Register(new HttpFolderResource("/Test19", "Data", true, false, true, false));

            HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("http://localhost:8080/Test19/String2.txt");

            Request.Method = "PUT";
            Request.Headers.Add("Content-Range: bytes 20-39/40");
            byte[] Data = new byte[20];
            int    i;

            for (i = 0; i < 20; i++)
            {
                Data[i] = (byte)'1';
            }

            Stream f = Request.GetRequestStream();

            f.Write(Data, 0, 20);

            WebResponse Response = Request.GetResponse();

            Response.Close();

            for (i = 0; i < 20; i++)
            {
                Data[i] = (byte)'2';
            }

            Request        = (HttpWebRequest)WebRequest.Create("http://localhost:8080/Test19/String2.txt");
            Request.Method = "PUT";
            Request.Headers.Add("Content-Range: bytes 0-19/40");

            f = Request.GetRequestStream();
            f.Write(Data, 0, 20);

            Response = Request.GetResponse();
            Response.Close();

            using (CookieWebClient Client = new CookieWebClient())
            {
                Data = Client.DownloadData("http://localhost:8080/Test19/String2.txt");
                string s = Encoding.ASCII.GetString(Data);

                Assert.AreEqual("2222222222222222222211111111111111111111", s);
            }
        }
Пример #15
0
        public void Test_27_Content_Conversion()
        {
            HttpFolderResource Resource = new HttpFolderResource("/Test27", "Data", false, false, true, false);

            Resource.AllowTypeConversion("text/plain", "text/x-test1", "text/x-test2", "text/x-test3");

            server.Register(Resource);

            using (CookieWebClient Client = new CookieWebClient())
            {
                Client.Accept = "text/x-test3";
                byte[]       Data = Client.DownloadData("http://localhost:8080/Test27/Text.txt");
                MemoryStream ms   = new MemoryStream(Data);
                StreamReader r    = new StreamReader(ms);
                string       s    = r.ReadToEnd();
                Assert.AreEqual("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\nConverter 1 was here.\r\nConverter 2 was here.\r\nConverter 3 was here.", s);
            }
        }
Пример #16
0
        public void Test_02_GET_HTTP_Chunked()
        {
            server.Register("/test02.txt", (req, resp) =>
            {
                int i;

                resp.ContentType = "text/plain";
                for (i = 0; i < 1000; i++)
                {
                    resp.Write(new string('a', 100));
                }
            });

            using (CookieWebClient Client = new CookieWebClient())
            {
                byte[] Data = Client.DownloadData("http://localhost:8080/test02.txt");
                string s    = Encoding.UTF8.GetString(Data);
                Assert.AreEqual(new string('a', 100000), s);
            }
        }