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 header = new HttpResponseHeader(oce.HeaderElements[i].Name, oce.HeaderElements[i].Value);
             headers.Add(header);
         }
     }
     ArrayList buffers = null;
     if ((oce.ResponseElements != null) && (oce.ResponseElements.Count > 0))
     {
         buffers = new ArrayList(oce.ResponseElements.Count);
         for (int j = 0; j < oce.ResponseElements.Count; j++)
         {
             ResponseElement element = oce.ResponseElements[j];
             IHttpResponseElement element2 = null;
             if (element is FileResponseElement)
             {
                 HttpContext current = HttpContext.Current;
                 HttpWorkerRequest request = (current != null) ? current.WorkerRequest : null;
                 bool supportsLongTransmitFile = (request != null) && request.SupportsLongTransmitFile;
                 bool isImpersonating = ((current != null) && current.IsClientImpersonationConfigured) || HttpRuntime.IsOnUNCShareInternal;
                 FileResponseElement element3 = (FileResponseElement) element;
                 element2 = new HttpFileResponseElement(element3.Path, element3.Offset, element3.Length, isImpersonating, supportsLongTransmitFile);
             }
             else if (element is MemoryResponseElement)
             {
                 MemoryResponseElement element4 = (MemoryResponseElement) element;
                 int size = System.Convert.ToInt32(element4.Length);
                 element2 = new HttpResponseBufferElement(element4.Buffer, size);
             }
             else
             {
                 if (!(element is SubstitutionResponseElement))
                 {
                     throw new NotSupportedException();
                 }
                 SubstitutionResponseElement element5 = (SubstitutionResponseElement) element;
                 element2 = new HttpSubstBlockResponseElement(element5.Callback);
             }
             buffers.Add(element2);
         }
     }
     else
     {
         buffers = new ArrayList();
     }
     return new CachedRawResponse(new HttpRawResponse(oce.StatusCode, oce.StatusDescription, headers, buffers, false), oce.Settings, oce.KernelCacheUrl, oce.CachedVaryId);
 }
예제 #2
0
        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;
        }