Example #1
0
        public async Task ExamplePartion()
        {
            // Applications should be entirely seperate instances. If they are not, you are not
            // performing a simulation.
            AppFunc app1 = CreateApplication("instance1");
            AppFunc app2 = CreateApplication("instance2");

            var settings = new FakeReverseProxySettings();

            // Here we're partioning the paths to different servers
            settings.Forward("/path1/").To(app1, new Uri("http://backend1.example.com/app1/"));
            settings.Forward("/path2/").To(app2, new Uri("http://backend2.example.com/app2/"));

            var reverseProxy = new FakeReverseProxy(settings);
            var handler      = new OwinHttpMessageHandler(reverseProxy.AppFunc)
            {
                AllowAutoRedirect = true,
                UseCookies        = true
            };

            using (var client = new HttpClient(handler)
            {
                BaseAddress = new Uri("http://example.com/")
            })
            {
                // Should hit app1
                var response = await client.GetAsync("/path1/");

                var body = await response.Content.ReadAsStringAsync();

                body.Should().Be("instance1");

                // Should hit app2
                response = await client.GetAsync("/path2/");

                body = await response.Content.ReadAsStringAsync();

                body.Should().Be("instance2");
            }
        }
        public async Task ExampleRoundRobin()
        {
            AppFunc app1 = CreateApplication("instance1");
            AppFunc app2 = CreateApplication("instance2");

            var settings = new FakeReverseProxySettings();

            // Here we're round-robining a path to two seperate apps
            settings.Forward("/path/")
            .To(app1, new Uri("http://backend1.example.com/pathX/"))
            .To(app2, new Uri("http://backend2.example.com/pathY/"));

            var reverseProxy = new FakeReverseProxy(settings);
            var handler      = new OwinHttpMessageHandler(reverseProxy.AppFunc)
            {
                AllowAutoRedirect = true,
                UseCookies        = true
            };

            using (var client = new HttpClient(handler)
            {
                BaseAddress = new Uri("http://example.com/")
            })
            {
                // Should hit app1
                var response = await client.GetAsync("/path/");

                var body = await response.Content.ReadAsStringAsync();

                body.Should().Be("instance1");

                // Should hit app2
                response = await client.GetAsync("/path/");

                body = await response.Content.ReadAsStringAsync();

                body.Should().Be("instance2");
            }
        }
 public static Func <Func <IDictionary <string, object>, Task>, Func <IDictionary <string, object>, Task> > CreateMiddleware(FakeReverseProxySettings settings)
 {
     if (settings == null)
     {
         throw new ArgumentNullException("settings");
     }
     return(next => env =>
     {
         throw new NotImplementedException();
     });
 }