private static List<HttpHeader> ReadResponseHeaders(HttpWebSession response)
        {
            for (var i = 0; i < response.Response.ResponseHeaders.Count; i++)
            {
                switch (response.Response.ResponseHeaders[i].Name.ToLower())
                {
                    case "content-length":
                        response.Response.ContentLength = int.Parse(response.Response.ResponseHeaders[i].Value.Trim());
                        break;

                    case "content-encoding":
                        response.Response.ContentEncoding = response.Response.ResponseHeaders[i].Value.Trim().ToLower();
                        break;

                    case "content-type":
                        if (response.Response.ResponseHeaders[i].Value.Contains(";"))
                        {
                            response.Response.ContentType = response.Response.ResponseHeaders[i].Value.Split(';')[0].Trim();
                            response.Response.CharacterSet = response.Response.ResponseHeaders[i].Value.Split(';')[1].ToLower().Replace("charset=", string.Empty).Trim();
                        }
                        else
                            response.Response.ContentType = response.Response.ResponseHeaders[i].Value.ToLower().Trim();
                        break;

                    case "transfer-encoding":
                        if (response.Response.ResponseHeaders[i].Value.ToLower().Contains("chunked"))
                            response.Response.IsChunked = true;
                        break;

                    case "connection":
                        if (response.Response.ResponseHeaders[i].Value.ToLower().Contains("close"))
                            response.Response.ResponseKeepAlive = false;
                        break;

                    default:
                        break;
                }
            }

             return response.Response.ResponseHeaders;
        }
        private static void SetRequestHeaders(List<HttpHeader> requestHeaders, HttpWebSession webRequest)
        {
            for (var i = 0; i < requestHeaders.Count; i++)
            {
                switch (requestHeaders[i].Name.ToLower())
                {
                    case "accept-encoding":
                        requestHeaders[i].Value = "gzip,deflate,zlib";
                        break;
                    case "connection":
                        if (requestHeaders[i].Value.ToLower() == "keep-alive")
                            webRequest.Request.KeepAlive = true;
                        break;
                    case "content-length":
                        int contentLen;
                        int.TryParse(requestHeaders[i].Value, out contentLen);
                        if (contentLen != 0)
                            webRequest.Request.ContentLength = contentLen;
                        break;
                    case "content-type":
                        webRequest.Request.ContentType = requestHeaders[i].Value;
                        break;
                    case "host":
                        webRequest.Request.Hostname = requestHeaders[i].Value;
                        break;
                    case "proxy-connection":
                        if (requestHeaders[i].Value.ToLower() == "keep-alive")
                            webRequest.Request.KeepAlive = true;
                        else if (requestHeaders[i].Value.ToLower() == "close")
                            webRequest.Request.KeepAlive = false;
                        break;

                    case "upgrade":
                        if (requestHeaders[i].Value.ToLower() == "websocket")
                            webRequest.Request.UpgradeToWebSocket = true;
                        break;

                    //revisit this, transfer-encoding is not a request header according to spec
                    //But how to identify if client is sending chunked body for PUT/POST?
                    case "transfer-encoding":
                        if (requestHeaders[i].Value.ToLower().Contains("chunked"))
                            webRequest.Request.SendChunked = true;
                        else
                            webRequest.Request.SendChunked = false;
                        break;

                    default:
                        break;
                }
            }
            FixRequestProxyHeaders(requestHeaders);
            webRequest.Request.RequestHeaders = requestHeaders;
        }
 internal SessionEventArgs(int bufferSize)
 {
     _bufferSize = bufferSize;
     Client = new Client();
     ProxySession = new HttpWebSession();
 }