Beispiel #1
0
        public async Task Host_Added(string startValue, string host, bool append, string expected)
        {
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Host = string.IsNullOrEmpty(host) ? new HostString() : new HostString(host);
            var proxyRequest = new HttpRequestMessage();

            proxyRequest.Headers.Add("name", startValue.Split(";", StringSplitOptions.RemoveEmptyEntries));
            var transform = new RequestHeaderXForwardedHostTransform("name", append);
            await transform.ApplyAsync(new RequestTransformContext()
            {
                HttpContext   = httpContext,
                ProxyRequest  = proxyRequest,
                HeadersCopied = true,
            });

            if (string.IsNullOrEmpty(expected))
            {
                Assert.False(proxyRequest.Headers.TryGetValues("name", out var _));
            }
            else
            {
                Assert.Equal(expected.Split(";", StringSplitOptions.RemoveEmptyEntries), proxyRequest.Headers.GetValues("name"));
            }
        }
Beispiel #2
0
        public void Host_Added(string startValue, string host, bool append, string expected)
        {
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Host = string.IsNullOrEmpty(host) ? new HostString() : new HostString(host);
            var transform = new RequestHeaderXForwardedHostTransform(append);
            var result    = transform.Apply(httpContext, new HttpRequestMessage(), startValue.Split(";", System.StringSplitOptions.RemoveEmptyEntries));

            Assert.Equal(expected.Split(";", System.StringSplitOptions.RemoveEmptyEntries), result);
        }