Beispiel #1
0
        public async Task Should_RewriteResponseContext(string url, string method, bool redirectHttps)
        {
            var domainConfiguration = new DomainConfiguration
            {
                HttpsRedirect = redirectHttps
            };

            hostResolver.Setup(x => x.GetMathingCofinguration(It.IsAny <HttpRequest>()))
            .Returns(domainConfiguration);

            hostResolver.Setup(x => x.GetHostUri(It.IsAny <HttpRequest>(), It.IsAny <DomainConfiguration>()))
            .Returns(new Uri("http://dummy.com"));

            var hostClient = new HostClient(httpClient, hostResolver.Object, exposedConfig);

            SetRequestMethod(method);

            await hostClient.ReverseProxy(httpContext);

            Assert.AreEqual(3, httpContext.Response.Headers.Count);

            Assert.AreEqual("1", httpContext.Response.Headers["CustomHeader"].ToString());
            Assert.AreEqual("2", httpContext.Response.Headers["CustomHeader2"].ToString());

            httpContext.Response.Body.Flush();
            httpContext.Response.Body.Position = 0;

            using (var bodyStream = new StreamReader(httpContext.Response.Body))
            {
                Assert.AreEqual(responseBodyString, bodyStream.ReadToEnd());
            }
        }
 public async Task Invoke(HttpContext httpContext, HostClient hostClient)
 {
     await hostClient.ReverseProxy(httpContext).ConfigureAwait(false);
 }