Beispiel #1
0
        public void Should_not_find_match(string location)
        {
            var settings = new FakeReverseProxySettings();

            settings
            .Forward("/some/path")
            .To(env => Task.FromResult(0), new Uri("http://internal.example.com/link/"));

            var forwardEntry = settings.FindForwardEntry(location);

            forwardEntry.Should().BeNull();
        }
Beispiel #2
0
        public void Should_find_match(string location, string expectedProxiedUrl)
        {
            var settings = new FakeReverseProxySettings();

            settings
            .Forward(location)
            .To(env => Task.FromResult(0), new Uri("http://internal.example.com/link/"));

            var forwardEntry = settings.FindForwardEntry("/some/path/page.html");
            var url          = forwardEntry.GetUri("/some/path/page.html");

            forwardEntry.Should().NotBeNull();
            url.ToString().Should().Be(expectedProxiedUrl);
        }
Beispiel #3
0
        public FakeReverseProxy(FakeReverseProxySettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            AppFunc = async env =>
            {
                var          context      = new OwinContext(env);
                ForwardEntry forwardEntry = settings.FindForwardEntry(context.Request.Uri.AbsolutePath);
                if (forwardEntry != null)
                {
                    await forwardEntry.Forward(env);

                    return;
                }

                context.Response.StatusCode   = 500;
                context.Response.ReasonPhrase = "Internal Server Error";
                await context.Response.WriteAsync("Unknown host");
            };
        }