예제 #1
0
        public FakeReverseProxyTests()
        {
            _sut = null;
            AppFunc proxiedAppFunc = async env =>
            {
                var context = new OwinContext(env);
                _sut = context;
                context.Response.StatusCode   = 200;
                context.Response.ReasonPhrase = "OK";
                await context.Response.WriteAsync("Hello");
            };
            var settings = new FakeReverseProxySettings();

            settings
            .Forward("/some/path/")
            .To(proxiedAppFunc, new Uri("http://internal1.example.com:8080/link/"));

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

            _client = new HttpClient(handler)
            {
                BaseAddress = new Uri("https://example.com")
            };
        }
예제 #2
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();
        }
예제 #3
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);
        }
예제 #4
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");
            };
        }