public void Test14()
        {
            _listener = NetworkHelpers.CreateAndStartHttpListener("http://127.0.0.1:", out var port, "/test14/");
            MyNetworkStream ns = CreateNS(port);

            Send(ns, "POST /test14/ HTTP/1.0\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
            HttpListenerContext c = _listener.GetContext();

            test14_request = c.Request;
            test_evt       = new ManualResetEvent(false);
            Thread thread = new Thread(ReadToEnd);

            thread.Start();
            if (test_evt.WaitOne(3000, false) == false)
            {
#if MONO_FEATURE_THREAD_ABORT
                thread.Abort();
#else
                thread.Interrupt();
#endif
                test_evt.Close();
                Assert.IsTrue(false, "Timed out");
            }
            test_evt.Close();
            c.Response.Close();
            ns.Close();
            Assert.AreEqual("123", read_to_end, "Did not get the expected input.");
        }
        public void Test16()
        {
            // 1 single write with headers + body (size > 8kB)
            _listener = CreateAndStartListener("http://127.0.0.1:9000/test16/");
            MyNetworkStream ns = CreateNS(9000);
            StringBuilder   sb = new StringBuilder();

            sb.Append("POST /test16/ HTTP/1.0\r\nHost: 127.0.0.1\r\nContent-Length: 8888\r\n\r\n");
            string eights = new string ('b', 8888);

            sb.Append(eights);
            string data = sb.ToString();

            Send(ns, data);
            HttpListenerContext c   = _listener.GetContext();
            HttpListenerRequest req = c.Request;

            using (StreamReader r = new StreamReader(req.InputStream)) {
                read_to_end = r.ReadToEnd();
            }
            Assert.AreEqual(read_to_end.Length, read_to_end.Length, "Wrong length");
            Assert.IsTrue(eights == read_to_end, "Wrong data");
            c.Response.Close();
            ns.Close();
        }
Exemple #3
0
		public void Test13 ()
		{
			// 0.9
			_listener = CreateAndStartListener ("http://127.0.0.1:9000/test13/");
			MyNetworkStream ns = CreateNS (9000);
			Send (ns, "GEt /test13/ HTTP/0.9\r\nHost: 127.0.0.1\r\n\r\n");
			ns.GetSocket ().Shutdown (SocketShutdown.Send);
			string input = Receive (ns, 512);
			ns.Close ();
			Assert.IsTrue (input.StartsWith ("HTTP/1.1 400"));
		}
		public void Test12 ()
		{
			// 0.9
			_listener = NetworkHelpers.CreateAndStartHttpListener ("http://127.0.0.1:", out var port, "/test12/");
			MyNetworkStream ns = CreateNS (port);
			Send (ns, "POST /test12/ HTTP/0.9\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
			ns.GetSocket ().Shutdown (SocketShutdown.Send);
			string input = Receive (ns, 512);
			ns.Close ();
			Assert.IsTrue(input.StartsWith ("HTTP/1.1 400"));
		}
Exemple #5
0
 public void Test12()
 {
     // 0.9
     using (HttpListener listener = CreateAndStartListener("http://127.0.0.1:9000/test12/")) {
         MyNetworkStream ns = CreateNS(9000);
         Send(ns, "POST /test12/ HTTP/0.9\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
         ns.GetSocket().Shutdown(SocketShutdown.Send);
         string input = Receive(ns, 512);
         ns.Close();
         Assert.IsTrue(input.StartsWith("HTTP/1.1 400"));
     }
 }
Exemple #6
0
		public void Test10 ()
		{
			// Same as Test9, but now we shutdown the socket for sending.
			_listener = CreateAndStartListener ("http://127.0.0.1:9000/test10/");
			MyNetworkStream ns = CreateNS (9000);
			Send (ns, "POST /test10/ HTTP/1.0\r\nHost: 127.0.0.1\r\nTransfer-Encoding: chunked\r\n\r\n3\r\n123\r\n0\r\n\r\n");
			ns.GetSocket ().Shutdown (SocketShutdown.Send);
			bool timeout;
			string response = ReceiveWithTimeout (ns, 512, 1000, out timeout);
			ns.Close ();
			Assert.IsFalse (timeout);
			Assert.IsTrue (response.StartsWith ("HTTP/1.1 411"));
		}
Exemple #7
0
        public void Test11()
        {
            var port = NetworkHelpers.FindFreePort();

            // 0.9
            _listener = CreateAndStartListener("http://127.0.0.1:" + port + "/test11/");
            MyNetworkStream ns = CreateNS(port);

            Send(ns, "POST /test11/ HTTP/0.9\r\nHost: 127.0.0.1\r\n\r\n123");
            ns.GetSocket().Shutdown(SocketShutdown.Send);
            string input = Receive(ns, 512);

            ns.Close();
            Assert.IsTrue(input.StartsWith("HTTP/1.1 400"));
        }
Exemple #8
0
		public void Test15 ()
		{
			// 2 separate writes -> 2 packets. Body size > 8kB
			_listener = CreateAndStartListener ("http://127.0.0.1:9000/test15/");
			MyNetworkStream ns = CreateNS (9000);
			Send (ns, "POST /test15/ HTTP/1.0\r\nHost: 127.0.0.1\r\nContent-Length: 8888\r\n\r\n");
			Thread.Sleep (800);
			string data = new string ('a', 8888);
			Send (ns, data);
			HttpListenerContext c = _listener.GetContext ();
			HttpListenerRequest req = c.Request;
			using (StreamReader r = new StreamReader (req.InputStream)) {
				read_to_end = r.ReadToEnd ();
			}
			Assert.AreEqual (read_to_end.Length, data.Length, "Wrong length");
			Assert.IsTrue (data == read_to_end, "Wrong data");
			c.Response.Close ();
			ns.Close ();
		}
Exemple #9
0
		public void Test14 ()
		{
			_listener = CreateAndStartListener ("http://127.0.0.1:9000/test14/");
			MyNetworkStream ns = CreateNS (9000);
			Send (ns, "POST /test14/ HTTP/1.0\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
			HttpListenerContext c = _listener.GetContext ();
			test14_request = c.Request;
			test_evt = new ManualResetEvent (false);
			Thread thread = new Thread (ReadToEnd);
			thread.Start ();
			if (test_evt.WaitOne (3000, false) == false) {
				thread.Abort ();
				test_evt.Close ();
				Assert.IsTrue (false, "Timed out");
			}
			test_evt.Close ();
			c.Response.Close ();
			ns.Close ();
			Assert.AreEqual ("123", read_to_end, "Did not get the expected input.");
		}