コード例 #1
0
        public void TakeHeader_HeadersNotCopied_ReturnsHttpContentHeader()
        {
            var httpContext   = new DefaultHttpContext();
            var proxyResponse = new HttpResponseMessage();

            proxyResponse.Content = new StringContent("hello world");
            proxyResponse.Content.Headers.Add("Name", "value2");
            var result = ResponseTransform.TakeHeader(new ResponseTransformContext()
            {
                HttpContext   = httpContext,
                ProxyResponse = proxyResponse,
                HeadersCopied = false,
            }, "name");

            Assert.Equal("value2", result);
        }
コード例 #2
0
        public void TakeHeader_RemovesAndReturnsHttpResponseHeader(bool copiedHeaders)
        {
            var httpContext = new DefaultHttpContext();

            httpContext.Response.Headers.Add("name", "value0");
            var proxyResponse = new HttpResponseMessage();

            proxyResponse.Headers.Add("Name", "value1");
            proxyResponse.Content = new StringContent("hello world");
            proxyResponse.Content.Headers.Add("Name", "value2");
            var result = ResponseTransform.TakeHeader(new ResponseTransformContext()
            {
                HttpContext   = httpContext,
                ProxyResponse = proxyResponse,
                HeadersCopied = copiedHeaders,
            }, "name");

            Assert.Equal("value0", result);
            Assert.False(httpContext.Response.Headers.TryGetValue("name", out var _));
            Assert.Equal(new[] { "value1" }, proxyResponse.Headers.GetValues("name"));
            Assert.Equal(new[] { "value2" }, proxyResponse.Content.Headers.GetValues("name"));
        }