Esempio n. 1
0
        public IStumpsServer CreateServer(int listeningPort, Uri remoteServerUri)
        {
            var server = new StumpsServer
            {
                ListeningPort    = listeningPort,
                RemoteHttpServer = remoteServerUri
            };

            return(server);
        }
Esempio n. 2
0
        public IStumpsServer CreateServer(int listeningPort, FallbackResponse fallbackResponse)
        {
            var server = new StumpsServer
            {
                ListeningPort   = listeningPort,
                DefaultResponse = fallbackResponse
            };

            return(server);
        }
Esempio n. 3
0
        public IStumpsServer CreateServer(int listeningPort, Uri remoteServerUri)
        {
            var server = new StumpsServer
            {
                ListeningPort = listeningPort,
                RemoteHttpServer = remoteServerUri
            };

            return server;
        }
Esempio n. 4
0
        public IStumpsServer CreateServer(int listeningPort, FallbackResponse fallbackResponse)
        {
            var server = new StumpsServer
            {
                ListeningPort = listeningPort,
                DefaultResponse = fallbackResponse
            };

            return server;
        }
Esempio n. 5
0
        /// <summary>
        ///     Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The command-line ar
        public static void Main(string[] args)
        {
            ConsoleHelper.ApplicationBanner("Hello World (Multiple Response) Fluent API");

            // Create a new Stumps Server
            var server = new StumpsServer().RespondsWithHttp404();

            // Showing off the multi-response behavior. When the URL /HelloWorld.htm is requested,
            // return back multiple HTML pages that are loaded from a file at random.
            var randomResponseStump = server
                                      .HandlesRequest("HelloWorld").MatchingMethod("GET")
                                      .MatchingUrl("/HelloWorld.htm")
                                      .ReturnsMultipleResponses(ResponseFactoryBehavior.Random);

            randomResponseStump.Responds().WithFile("HelloWorld1.htm");
            randomResponseStump.Responds().WithFile("HelloWorld2.htm");
            randomResponseStump.Responds().WithFile("HelloWorld3.htm");

            // Showing off the ability to drop a connection for an incomming URL
            server.HandlesRequest("HelloDrop").MatchingMethod("GET")
            .MatchingUrl("/HelloDrop.htm")
            .Responds().ByDroppingTheConnection();

            // Showing off the ability to mix and match the delay and terminate connection
            // features within a sequence using the default looping behavior.
            var mixedStump = server
                             .HandlesRequest("HelloMixed").MatchingMethod("GET")
                             .MatchingUrl("/HelloMixed.htm");

            mixedStump.Responds().WithFile("HelloWorld1.htm");
            mixedStump.Responds().WithFile("HelloWorld2.htm").DelayedBy(2000);
            mixedStump.Responds().WithFile("HelloWorld3.htm");
            mixedStump.Responds().ByDroppingTheConnection();

            // Showing off a stump
            // Show the requests that are incomming
            server.RequestProcessed += (o, e) => ConsoleHelper.ShowHttpResponse(server, e);

            // Start the server and wait!
            server.Start();

            // Show the URL to the user
            Console.WriteLine("Browse to http://localhost:{0}/HelloWorld.htm", server.ListeningPort);
            Console.WriteLine();

            // Wait to exit
            ConsoleHelper.WaitForExit();

            server.Shutdown();
            server.Dispose();
        }
Esempio n. 6
0
        /// <summary>
        ///     Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            ConsoleHelper.ApplicationBanner("Hello World API");

            // Create a new Stumps Server
            var server = new StumpsServer();

            // An open port will be chosen automatically unless specified
            // server.ListensOnPort = 9100;

            // Create a new Stump for the server
            var stump = new Stump("HelloWorldStump");

            // Add two rules that stumps out HTTP GET requests for the url /HeloWorld.htm
            stump.AddRule(new HttpMethodRule("GET"));
            stump.AddRule(new UrlRule("/HelloWorld.htm"));

            // Create a response for the rule
            var response = new BasicHttpResponse();

            response.Headers["Content-Type"] = "text/html;charset=UTF-8";
            response.AppendToBody(
                "<html><header><title>Stumps Hello World</title></header><body><p>Hello From Stumps</p></body></html>");

            // Add the response to the stump
            stump.Responses = new StumpResponseFactory();
            stump.Responses.Add(response);

            // Add the stump to the server
            server.AddStump(stump);

            // Show the requests that are incomming
            server.RequestProcessed += (o, e) => ConsoleHelper.ShowHttpResponse(server, e);

            // Start the server and wait!
            server.Start();

            // Show the URL to the user
            Console.WriteLine("Browse to http://localhost:{0}/HelloWorld.htm", server.ListeningPort);
            Console.WriteLine();

            // Wait to exit
            ConsoleHelper.WaitForExit();

            server.Shutdown();
            server.Dispose();
        }
Esempio n. 7
0
        /// <summary>
        ///     Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            ConsoleHelper.ApplicationBanner("Hello World Fluent API");

            // Create a new Stumps Server
            var server = new StumpsServer();

            // Showing off some chaining: Make the server return an HTTP 404 for all unknown
            // and then when the URL /HelloWorld.htm is requested, return back an HTML page
            // that was loaded from a file, but the response is delayed by 2000 milliseconds.
            server.RespondsWithHttp404()
            .HandlesRequest("HelloWorld").MatchingMethod("GET")
            .MatchingUrl("/HelloWorld.htm")
            .Responds().WithFile("HelloWorld.htm")
            .DelayedBy(2000);

            // Showing off the ability to drop a connection for an incomming URL
            server.HandlesRequest("HelloDrop").MatchingMethod("GET")
            .MatchingUrl("/HelloDrop.htm")
            .Responds().ByDroppingTheConnection();

            // Showing off a stump
            // Show the requests that are incomming
            server.RequestProcessed += (o, e) => ConsoleHelper.ShowHttpResponse(server, e);

            // Start the server and wait!
            server.Start();

            // Show the URL to the user
            Console.WriteLine("Browse to http://localhost:{0}/HelloWorld.htm", server.ListeningPort);
            Console.WriteLine();

            // Wait to exit
            ConsoleHelper.WaitForExit();

            server.Shutdown();
            server.Dispose();
        }