internal CachedRawResponse(HttpRawResponse rawResponse, HttpCachePolicySettings settings, string kernelCacheUrl, Guid cachedVaryId)
 {
     this._rawResponse = rawResponse;
     this._settings = settings;
     this._kernelCacheUrl = kernelCacheUrl;
     this._cachedVaryId = cachedVaryId;
 }
 private static bool IsSubstBlockSerializable(HttpRawResponse rawResponse) {
     if (!rawResponse.HasSubstBlocks)
         return true;
     for (int i = 0; i < rawResponse.Buffers.Count; i++) {
         HttpSubstBlockResponseElement substBlock = rawResponse.Buffers[i] as HttpSubstBlockResponseElement;
         if (substBlock == null)
             continue;
         if (!substBlock.Callback.Method.IsStatic)
             return false;
     }
     return true;
 }
        private static CachedRawResponse Convert(OutputCacheEntry oce) {            
            ArrayList headers = null;
            if (oce.HeaderElements != null && oce.HeaderElements.Count > 0) {
                headers = new ArrayList(oce.HeaderElements.Count);
                for (int i = 0; i < oce.HeaderElements.Count; i++) {
                    HttpResponseHeader h = new HttpResponseHeader(oce.HeaderElements[i].Name, oce.HeaderElements[i].Value);
                    headers.Add(h);
                }                
            }

            ArrayList buffers = null;
            if (oce.ResponseElements != null && oce.ResponseElements.Count > 0) {
                buffers = new ArrayList(oce.ResponseElements.Count);
                for (int i = 0; i < oce.ResponseElements.Count; i++) {
                    ResponseElement re = oce.ResponseElements[i];
                    IHttpResponseElement elem = null;
                    if (re is FileResponseElement) {
                        HttpContext context = HttpContext.Current;
                        HttpWorkerRequest wr = (context != null) ? context.WorkerRequest : null;
                        bool supportsLongTransmitFile = (wr != null && wr.SupportsLongTransmitFile);
                        bool isImpersonating = ((context != null && context.IsClientImpersonationConfigured) || HttpRuntime.IsOnUNCShareInternal);
                        FileResponseElement fre = (FileResponseElement)re;

                        // DevDiv #21203: Need to verify permission to access the requested file since handled by native code.
                        HttpRuntime.CheckFilePermission(fre.Path);

                        elem = new HttpFileResponseElement(fre.Path, fre.Offset, fre.Length, isImpersonating, supportsLongTransmitFile);
                    }
                    else if (re is MemoryResponseElement) {
                        MemoryResponseElement mre = (MemoryResponseElement)re;
                        int size = System.Convert.ToInt32(mre.Length);
                        elem = new HttpResponseBufferElement(mre.Buffer, size);
                    }
                    else if (re is SubstitutionResponseElement) {
                        SubstitutionResponseElement sre = (SubstitutionResponseElement)re;
                        elem = new HttpSubstBlockResponseElement(sre.Callback);                        
                    }
                    else {
                        throw new NotSupportedException();
                    }
                    buffers.Add(elem);
                }
            }
            else {
                buffers = new ArrayList();
            }
            
            HttpRawResponse rawResponse = new HttpRawResponse(oce.StatusCode, oce.StatusDescription, headers, buffers, false /*hasSubstBlocks*/);
            CachedRawResponse cachedRawResponse = new CachedRawResponse(rawResponse, oce.Settings, oce.KernelCacheUrl, oce.CachedVaryId);

            return cachedRawResponse;
        }
 internal void UseSnapshot(HttpRawResponse rawResponse, bool sendBody)
 {
     if (this._headersWritten)
     {
         throw new HttpException(System.Web.SR.GetString("Cannot_use_snapshot_after_headers_sent"));
     }
     if (this._httpWriter == null)
     {
         throw new HttpException(System.Web.SR.GetString("Cannot_use_snapshot_for_TextWriter"));
     }
     this.ClearAll();
     this.StatusCode = rawResponse.StatusCode;
     this.StatusDescription = rawResponse.StatusDescription;
     ArrayList headers = rawResponse.Headers;
     int num = (headers != null) ? headers.Count : 0;
     for (int i = 0; i < num; i++)
     {
         HttpResponseHeader header = (HttpResponseHeader) headers[i];
         this.AppendHeader(header.Name, header.Value);
     }
     this._httpWriter.UseSnapshot(rawResponse.Buffers);
     this._suppressContent = !sendBody;
 }
        // Send saved response snapshot as the entire response
        internal void UseSnapshot(HttpRawResponse rawResponse, bool sendBody) {
            if (_headersWritten)
                throw new HttpException(SR.GetString(SR.Cannot_use_snapshot_after_headers_sent));

            if (_httpWriter == null)
                throw new HttpException(SR.GetString(SR.Cannot_use_snapshot_for_TextWriter));

            ClearAll();

            // restore status
            StatusCode = rawResponse.StatusCode;
            StatusDescription = rawResponse.StatusDescription;

            // restore headers
            ArrayList headers = rawResponse.Headers;
            int n = (headers != null) ? headers.Count : 0;
            for (int i = 0; i < n; i++) {
                HttpResponseHeader h = (HttpResponseHeader)(headers[i]);
                this.AppendHeader(h.Name, h.Value);
            }

            // restore content
            _httpWriter.UseSnapshot(rawResponse.Buffers);

            _suppressContent = !sendBody;
        }
 internal CachedRawResponse(
           HttpRawResponse         rawResponse,
           HttpCachePolicySettings settings,
           String                  kernelCacheUrl,
           Guid                    cachedVaryId) {
     _rawResponse = rawResponse;
     _settings = settings;
     _kernelCacheUrl = kernelCacheUrl;
     _cachedVaryId = cachedVaryId;
 }
 private static bool IsSubstBlockSerializable(HttpRawResponse rawResponse)
 {
     if (rawResponse.HasSubstBlocks)
     {
         for (int i = 0; i < rawResponse.Buffers.Count; i++)
         {
             HttpSubstBlockResponseElement element = rawResponse.Buffers[i] as HttpSubstBlockResponseElement;
             if ((element != null) && !element.Callback.Method.IsStatic)
             {
                 return false;
             }
         }
     }
     return true;
 }