public void HttpRequestIgnoreBadCookies()
        {
            var          port     = NetworkHelpers.FindFreePort();
            HttpListener listener = HttpListener2Test.CreateAndStartListener(
                "http://127.0.0.1:" + port + "/HttpRequestIgnoreBadCookiesTest/");
            NetworkStream ns = HttpListener2Test.CreateNS(port);

            HttpListener2Test.Send(ns, "GET /HttpRequestIgnoreBadCookiesTest/?a=b HTTP/1.1\r\nHost: 127.0.0.1\r\nCookie: ELOQUA=GUID=5ca2346347357f4-f877-4eff-96aa-70fe0b677650; ELQSTATUS=OK; WRUID=609099666.123259461695; CommunityServer-UserCookie2101=lv=Thu, 26 Jul 2012 15:25:11 GMT&mra=Mon, 01 Oct 2012 17:40:05 GMT; PHPSESSID=1234dg3opfjb4qafp0oo645; __utma=9761706.1153317537.1357240270.1357240270.1357317902.2; __utmb=9761706.6.10.1357317902; __utmc=9761706; __utmz=9761706.1357240270.1.1.utmcsr=test.testdomain.com|utmccn=(referral)|utmcmd=referral|utmcct=/test/1234\r\n\r\n");
            HttpListenerContext ctx     = listener.GetContext();
            HttpListenerRequest request = ctx.Request;

            Assert.AreEqual("/HttpRequestIgnoreBadCookiesTest/?a=b", request.Url.PathAndQuery);
            listener.Close();
        }
        public void HttpRequestUriIsNotDecoded()
        {
            var          port     = NetworkHelpers.FindFreePort();
            HttpListener listener = HttpListener2Test.CreateAndStartListener(
                "http://127.0.0.1:" + port + "/RequestUriDecodeTest/");
            NetworkStream ns = HttpListener2Test.CreateNS(port);

            HttpListener2Test.Send(ns, "GET /RequestUriDecodeTest/?a=b&c=d%26e HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
            HttpListenerContext ctx     = listener.GetContext();
            HttpListenerRequest request = ctx.Request;

            Assert.AreEqual("/RequestUriDecodeTest/?a=b&c=d%26e", request.Url.PathAndQuery);
            listener.Close();
        }
        public void HttpMethod()
        {
            var          port     = NetworkHelpers.FindFreePort();
            HttpListener listener = HttpListener2Test.CreateAndStartListener(
                "http://127.0.0.1:" + port + "/HttpMethod/");
            NetworkStream ns = HttpListener2Test.CreateNS(port);

            HttpListener2Test.Send(ns, "pOsT /HttpMethod/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
            HttpListenerContext ctx     = listener.GetContext();
            HttpListenerRequest request = ctx.Request;

            Assert.AreEqual("pOsT", request.HttpMethod);
            listener.Close();
        }
예제 #4
0
        public void HttpBasicAuthScheme()
        {
            HttpListener listener = HttpListener2Test.CreateAndStartListener("http://*:9000/authTest/", AuthenticationSchemes.Basic);

            //dummy-wait for context
            listener.BeginGetContext(null, listener);
            NetworkStream ns = HttpListener2Test.CreateNS(9000);

            HttpListener2Test.Send(ns, "GET /authTest/ HTTP/1.0\r\n\r\n");
            String response = HttpListener2Test.Receive(ns, 512);

            Assert.IsTrue(response.Contains("WWW-Authenticate: Basic realm"), "#A");
            ns.Close();
            listener.Close();
        }
예제 #5
0
        public void Test_EmptyLineAtStart()
        {
            var listener = HttpListener2Test.CreateAndStartListener("http://127.0.0.1:9124/");
            var ns       = HttpListener2Test.CreateNS(9124);

            HttpListener2Test.Send(ns, "\r\nGET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");

            bool timedout;

            HttpListener2Test.GetContextWithTimeout(listener, 1000, out timedout);

            Assert.IsFalse(timedout, "timed out");

            ns.Close();
            listener.Close();
        }
예제 #6
0
        public void HttpRequestIsLocal()
        {
            var ips = new List <IPAddress> (Dns.GetHostAddresses(Dns.GetHostName()));

            ips.Add(IPAddress.Loopback);
            foreach (var ip in ips)
            {
                if (ip.AddressFamily != AddressFamily.InterNetwork)
                {
                    continue;
                }

                HttpListener listener = HttpListener2Test.CreateAndStartListener(
                    "http://" + ip + ":9000/HttpRequestIsLocal/");
                NetworkStream ns = HttpListener2Test.CreateNS(ip, 9000);
                HttpListener2Test.Send(ns, "GET /HttpRequestIsLocal/ HTTP/1.0\r\n\r\n");
                HttpListenerContext ctx     = listener.GetContext();
                HttpListenerRequest request = ctx.Request;
                Assert.AreEqual(true, request.IsLocal, "IP " + ip + " is not local");
                listener.Close();
            }
        }
예제 #7
0
        public void TestNonChunkedAsync()
        {
            var          port     = NetworkHelpers.FindFreePort();
            HttpListener listener = HttpListener2Test.CreateAndStartListener("http://127.0.0.1:" + port + "/");

            listener.BeginGetContext(callback, listener);

            HttpListener2Test.MyNetworkStream ns = HttpListener2Test.CreateNS(port);
            string message = "<script>\n" +
                             " <!-- register the blueprint for our show-headers service -->\n" +
                             " <action verb=\"POST\" path=\"/host/register\">\n" +
                             "    <blueprint>\n" +
                             "      <assembly>dream.tutorial.show-headers</assembly>\n" +
                             "      <class>MindTouch.Dream.Tutorial.ShowHeadersService</class>\n" +
                             "    </blueprint>\n" +
                             "  </action>\n" +
                             "\n" +
                             "  <!-- instantiate it -->\n" +
                             "  <action verb=\"POST\" path=\"/host/start\">\n" +
                             "    <config>\n" +
                             "      <path>show-headers</path>\n" +
                             "      <class>MindTouch.Dream.Tutorial.ShowHeadersService</class>\n" +
                             "    </config>\n" +
                             "  </action>\n" +
                             "</script>";
            string s = String.Format("POST / HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: {0}\r\n\r\n{1}",
                                     message.Length, message);

            HttpListener2Test.Send(ns, s);
            bool   timedout;
            string response = HttpListener2Test.ReceiveWithTimeout(ns, 1024, 3000, out timedout);

            ns.Close();
            listener.Close();
            Assert.IsFalse(timedout);
        }
예제 #8
0
		public void Test_MultipleConnections ()
		{
			HttpListener listener = HttpListener2Test.CreateAndStartListener ("http://127.0.0.1:9000/multiple/");

			// First one
			NetworkStream ns = HttpListener2Test.CreateNS (9000);
			HttpListener2Test.Send (ns, "POST /multiple/ HTTP/1.0\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
			HttpListenerContext ctx = listener.GetContext ();
			HttpListener2Test.Send (ctx.Response.OutputStream, "%%%OK%%%");
			ctx.Response.OutputStream.Close ();
			string response = HttpListener2Test.Receive (ns, 1024);
			ns.Close ();

			// Second one
			ns = HttpListener2Test.CreateNS (9000);
			HttpListener2Test.Send (ns, "POST /multiple/ HTTP/1.0\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
			ctx = listener.GetContext ();
			HttpListener2Test.Send (ctx.Response.OutputStream, "%%%OK%%%");
			ctx.Response.OutputStream.Close ();
			response = HttpListener2Test.Receive (ns, 1024);
			ns.Close ();
			
			listener.Close ();
		}
예제 #9
0
        [Category("NotWorking")]          // Bug #5742
        public void HasEntityBody()
        {
            HttpListenerContext ctx;
            HttpListenerRequest request;
            NetworkStream       ns;
            var          port     = NetworkHelpers.FindFreePort();
            HttpListener listener = HttpListener2Test.CreateAndStartListener(
                "http://127.0.0.1:" + port + "/HasEntityBody/");

            // POST with non-zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "POST /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#A");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // POST with zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "POST /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#B");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // POST with chunked encoding
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "POST /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#C");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // GET with no Content-Length
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "GET /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#D");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // GET with non-zero Content-Length
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "GET /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#E");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // GET with zero Content-Length
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "GET /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#F");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // GET with chunked encoding
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "GET /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#G");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // PUT with non-zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "PUT /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#H");

            // PUT with zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "PUT /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#I");

            // INVALID with non-zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "INVALID /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#J");

            // INVALID with zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "INVALID /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#K");

            // INVALID with chunked encoding
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "INVALID /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#L");

            listener.Close();
        }