Ejemplo n.º 1
0
        public void Nginx_SingleRequest()
        {
            AssertNginxInPath();

            var nginx          = StartNginx("ServerConfigs/NginxBasicConfig.conf");
            var expectedResult = "Hello World!";

            var app = new FCGIApplication();

            app.OnRequestReceived += (sender, request) =>
            {
                request.WriteResponseASCII("HTTP/1.1 200 OK\nContent-Type:text/html\n\n" + expectedResult);
                request.Close();
            };

            var appThread = new Thread(() => {
                app.Run(19000);
            });

            appThread.Start();

            var result = GetHttp("http://localhost:8182");

            app.Stop();
            StopNginx(nginx);

            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 2
0
        public void Nginx_ManyRequests_Keepalive()
        {
            AssertNginxInPath();

            var nginx          = StartNginx("ServerConfigs/NginxKeepalive.conf");
            var expectedResult = "Hello World!";

            var app = new FCGIApplication();

            app.OnRequestReceived += (sender, request) =>
            {
                request.WriteResponseASCII("HTTP/1.1 200 OK\nContent-Type:text/html\n\n" + expectedResult);
                request.Close();
            };

            var appThread = new Thread(() => {
                app.Run(19000);
            });

            appThread.Start();

            Task <string>[] results = new Task <string> [500];

            for (int i = 0; i < results.Length; i++)
            {
                results[i] = GetHttpAsync("http://localhost:8182");
                Thread.Sleep(20);
            }

            // Count the number of correct results
            int successCount = 0;
            // We will allow 2% of errors
            int minimumSuccessCount = (int)(results.Length * 0.95);

            for (int i = 0; i < results.Length; i++)
            {
                results[i].Wait(20000);

                var result = results[i].Result;
                if (result == expectedResult)
                {
                    successCount++;
                }
            }

            Assert.GreaterOrEqual(successCount, minimumSuccessCount, "At least 95% of requests should be successful");

            StopNginx(nginx);
            app.Stop();
            appThread.Join(500);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            // Create a new FCGIApplication, will accept FastCGI requests
            var app = new FCGIApplication();

            // Handle requests by responding with a 'Hello World' message
            app.OnRequestReceived += (sender, request) =>
            {
                request.WriteResponseASCII("HTTP/1.1 200 OK\nContent-Type:text/html\n\nHello World!");
                request.Close();
            };

            // Start listening on port 19000
            app.Run(19000);
        }
Ejemplo n.º 4
0
        public void Nginx_ManyRequests_Keepalive()
        {
            AssertNginxInPath();

            var nginx          = StartNginx("ServerConfigs/NginxKeepalive.conf");
            var expectedResult = "Hello World!";

            var app = new FCGIApplication();

            app.OnRequestReceived += (sender, request) =>
            {
                request.WriteResponseASCII("HTTP/1.1 200 OK\nContent-Type:text/html\n\n" + expectedResult);
                request.Close();
            };

            var appThread = new Thread(() => {
                app.Run(19000);
            });

            appThread.Start();

            Task <string>[] results = new Task <string> [1000];

            for (int i = 0; i < results.Length; i++)
            {
                results[i] = GetHttpAsync("http://localhost:8182");
                Thread.Sleep(1);
            }

            for (int i = 0; i < results.Length; i++)
            {
                results[i].Wait(20000);
                var result = results[i].Result;
                Assert.AreEqual(expectedResult, result);
            }

            StopNginx(nginx);
            app.Stop();
            appThread.Join(500);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // Create a new FCGIApplication, will accept FastCGI requests
            var app = new FCGIApplication();

            // Handle requests by responding with a 'Hello World' message
            app.OnRequestReceived += (sender, request) =>
            {
                StringBuilder responseString = new StringBuilder();
                //responseString.AppendLine ( "HTTP/1.1" );
                responseString.AppendLine("Status: 200 OK");
                responseString.AppendLine("Content-Type: text/html");
                //responseString.AppendLine("charset=utf-8");
                //responseString.AppendLine();
                responseString.AppendLine();
                responseString.AppendLine("Hello World!");

                request.WriteResponseASCII(responseString.ToString());
                request.Close();
            };

            // Start listening on port 19000
            app.Run(19000);
        }