示例#1
0
        internal HttpWebResponse(Uri responseUri, KnownHttpVerb verb, CoreResponseData coreData, string mediaType, bool usesProxySemantics, DecompressionMethods decompressionMethod)
        {
            m_Uri = responseUri;
            m_Verb = verb;
            m_MediaType = mediaType;
            m_UsesProxySemantics = usesProxySemantics;

            m_ConnectStream = coreData.m_ConnectStream;
            m_HttpResponseHeaders = coreData.m_ResponseHeaders;
            m_ContentLength = coreData.m_ContentLength;
            m_StatusCode = coreData.m_StatusCode;
            m_StatusDescription = coreData.m_StatusDescription;
            m_IsVersionHttp11 = coreData.m_IsVersionHttp11;

            //if the returned contentlength is zero, preemptively invoke calldone on the stream.
            //this will wake up any pending reads.
            if (m_ContentLength == 0 && m_ConnectStream is ConnectStream)
            {
                ((ConnectStream)m_ConnectStream).CallDone();
            }

            // handle Content-Location header, by combining it with the orginal request.
            string contentLocation = m_HttpResponseHeaders[HttpKnownHeaderNames.ContentLocation];

            if (contentLocation != null)
            {
                try
                {
                    m_Uri = new Uri(m_Uri, contentLocation);
                }
                catch (UriFormatException e)
                {
                    GlobalLog.Assert("Exception on response Uri parsing.", e.ToString());
                }
            }
            // decompress responses by hooking up a final response Stream - only if user required it
            if (decompressionMethod != DecompressionMethods.None)
            {
                string contentEncoding = m_HttpResponseHeaders[HttpKnownHeaderNames.ContentEncoding];
                if (contentEncoding != null)
                {
                    if (((decompressionMethod & DecompressionMethods.GZip) != 0) && contentEncoding.IndexOf(HttpWebRequest.GZipHeader) != -1)
                    {
                        m_ConnectStream = new GZipWrapperStream(m_ConnectStream, CompressionMode.Decompress);
                        m_ContentLength = -1; // unknown on compressed streams

                        // Setting a response header after parsing will ruin the Common Header optimization.
                        // This seems like a corner case.  ContentEncoding could be added as a common header, with a special
                        // property allowing it to be nulled.
                        m_HttpResponseHeaders[HttpKnownHeaderNames.ContentEncoding] = null;
                    }
                    else if (((decompressionMethod & DecompressionMethods.Deflate) != 0) && contentEncoding.IndexOf(HttpWebRequest.DeflateHeader) != -1)
                    {
                        m_ConnectStream = new DeflateWrapperStream(m_ConnectStream, CompressionMode.Decompress);
                        m_ContentLength = -1; // unknown on compressed streams

                        // Setting a response header after parsing will ruin the Common Header optimization.
                        // This seems like a corner case.  ContentEncoding could be added as a common header, with a special
                        // property allowing it to be nulled.
                        m_HttpResponseHeaders[HttpKnownHeaderNames.ContentEncoding] = null;
                    }
                }
            }
        }
示例#2
0
 protected HttpWebResponse(SerializationInfo serializationInfo, StreamingContext streamingContext)
     : base(serializationInfo, streamingContext)
 {
     m_HttpResponseHeaders = (WebHeaderCollection)serializationInfo.GetValue("m_HttpResponseHeaders", typeof(WebHeaderCollection));
     m_Uri = (Uri)serializationInfo.GetValue("m_Uri", typeof(Uri));
     #if !FEATURE_PAL
     m_Certificate = (X509Certificate)serializationInfo.GetValue("m_Certificate", typeof(X509Certificate));
     #endif // !FEATURE_PAL
     Version version = (Version)serializationInfo.GetValue("m_Version", typeof(Version));
     m_IsVersionHttp11 = version.Equals(HttpVersion.Version11);
     m_StatusCode = (HttpStatusCode)serializationInfo.GetInt32("m_StatusCode");
     m_ContentLength = serializationInfo.GetInt64("m_ContentLength");
     m_Verb = KnownHttpVerb.Parse(serializationInfo.GetString("m_Verb"));
     m_StatusDescription = serializationInfo.GetString("m_StatusDescription");
     m_MediaType = serializationInfo.GetString("m_MediaType");
 }