Beispiel #1
0
        internal HttpWebResponse(Uri uri, string method, WebResponseStream stream, CookieContainer container)
        {
            this.uri    = uri;
            this.method = method;
            this.stream = stream;

            webHeaders        = stream.Headers ?? new WebHeaderCollection();
            version           = stream.Version;
            statusCode        = stream.StatusCode;
            statusDescription = stream.StatusDescription ?? HttpStatusDescription.Get(statusCode);
            contentLength     = -1;

            try {
                string cl = webHeaders ["Content-Length"];
                if (String.IsNullOrEmpty(cl) || !Int64.TryParse(cl, out contentLength))
                {
                    contentLength = -1;
                }
            } catch (Exception) {
                contentLength = -1;
            }

            if (container != null)
            {
                this.cookie_container = container;
                FillCookies();
            }
        }
        internal HttpWebResponse(Uri uri, string method, WebResponseStream stream, CookieContainer container)
        {
            this.uri    = uri;
            this.method = method;
            this.stream = stream;

            webHeaders        = stream.Headers ?? new WebHeaderCollection();
            version           = stream.Version;
            statusCode        = stream.StatusCode;
            statusDescription = stream.StatusDescription ?? HttpStatusDescription.Get(statusCode);
            contentLength     = -1;

            try {
                string cl = webHeaders ["Content-Length"];
                if (String.IsNullOrEmpty(cl) || !Int64.TryParse(cl, out contentLength))
                {
                    contentLength = -1;
                }
            } catch (Exception) {
                contentLength = -1;
            }

            if (container != null)
            {
                this.cookie_container = container;
                FillCookies();
            }

            string content_encoding = webHeaders ["Content-Encoding"];

            if (content_encoding == "gzip" && (stream.Request.AutomaticDecompression & DecompressionMethods.GZip) != 0)
            {
                this.stream = new GZipStream(stream, CompressionMode.Decompress);
                webHeaders.Remove(HttpRequestHeader.ContentEncoding);
            }
            else if (content_encoding == "deflate" && (stream.Request.AutomaticDecompression & DecompressionMethods.Deflate) != 0)
            {
                this.stream = new DeflateStream(stream, CompressionMode.Decompress);
                webHeaders.Remove(HttpRequestHeader.ContentEncoding);
            }
        }