private void BuildResponse(IMutableWebResponse response, IWebResponse proxyResponse)
        {
            response.ProtocolVersion   = proxyResponse.ProtocolVersion;
            response.ContentType       = proxyResponse.ContentType;
            response.StatusCode        = (int)proxyResponse.StatusCode;
            response.StatusDescription = proxyResponse.StatusDescription;

            if (proxyResponse.ContentLength >= 0)
            {
                response.ContentLength = proxyResponse.ContentLength;
            }
            if (proxyResponse.Headers.ContainsKey("Content-Encoding") && !String.IsNullOrWhiteSpace(proxyResponse.ContentEncoding))
            {
                response.ContentEncoding = Encoding.GetEncoding(proxyResponse.ContentEncoding);
            }
            if (proxyResponse.Headers.ContainsKey("Location"))
            {
                response.RedirectLocation = proxyResponse.Headers["Location"];
            }
            if (proxyResponse.Headers.ContainsKey("Keep-Alive"))
            {
                bool keepAlive;
                if (Boolean.TryParse(proxyResponse.Headers["Keep-Alive"], out keepAlive))
                {
                    response.KeepAlive = keepAlive;
                }
            }

            foreach (var cookie in proxyResponse.Cookies)
            {
                response.Cookies.Add(cookie);
            }
            foreach (var header in proxyResponse.Headers)
            {
                if (header.Key.StartsWith("Proxy-"))
                {
                    continue; // Ignore proxy headers
                }
                if (PropertyHeaders.Contains(header.Key))
                {
                    continue;
                }

                response.Headers.Add(header.Key, header.Value);
            }

            var proxyStream   = proxyResponse.GetStream();
            var requestStream = response.GetStream();

            proxyStream.CopyTo(requestStream);
            requestStream.Close();
        }
        private static void CustomAction(IMutableWebResponse response, HttpStatusCode customResultStatus, Stream customResultStream)
        {
            if (customResultStatus == 0)
            {
                customResultStatus = HttpStatusCode.OK;
            }

            response.StatusCode = (int)customResultStatus;

            var responseStream = response.GetStream();

            customResultStream.CopyTo(responseStream);
            responseStream.Close();
        }