private static OutputCacheEntry Convert(CachedRawResponse cachedRawResponse, string depKey, string[] fileDependencies) { List <HeaderElement> headerElements = null; ArrayList headers = cachedRawResponse._rawResponse.Headers; int count = (headers != null) ? headers.Count : 0; for (int i = 0; i < count; i++) { if (headerElements == null) { headerElements = new List <HeaderElement>(count); } HttpResponseHeader h = (HttpResponseHeader)(headers[i]); headerElements.Add(new HeaderElement(h.Name, h.Value)); } List <ResponseElement> responseElements = null; ArrayList buffers = cachedRawResponse._rawResponse.Buffers; count = (buffers != null) ? buffers.Count : 0; for (int i = 0; i < count; i++) { if (responseElements == null) { responseElements = new List <ResponseElement>(count); } IHttpResponseElement elem = buffers[i] as IHttpResponseElement; if (elem is HttpFileResponseElement) { HttpFileResponseElement fileElement = elem as HttpFileResponseElement; responseElements.Add(new FileResponseElement(fileElement.FileName, fileElement.Offset, elem.GetSize())); } else if (elem is HttpSubstBlockResponseElement) { HttpSubstBlockResponseElement substElement = elem as HttpSubstBlockResponseElement; responseElements.Add(new SubstitutionResponseElement(substElement.Callback)); } else { byte[] b = elem.GetBytes(); long length = (b != null) ? b.Length : 0; responseElements.Add(new MemoryResponseElement(b, length)); } } OutputCacheEntry oce = new OutputCacheEntry( cachedRawResponse._cachedVaryId, cachedRawResponse._settings, cachedRawResponse._kernelCacheUrl, depKey, fileDependencies, cachedRawResponse._rawResponse.StatusCode, cachedRawResponse._rawResponse.StatusDescription, headerElements, responseElements ); return(oce); }
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)); }
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); }
private static OutputCacheEntry Convert(CachedRawResponse cachedRawResponse, string depKey, string[] fileDependencies) { List <HeaderElement> headerElements = null; ArrayList headers = cachedRawResponse._rawResponse.Headers; int capacity = (headers != null) ? headers.Count : 0; for (int i = 0; i < capacity; i++) { if (headerElements == null) { headerElements = new List <HeaderElement>(capacity); } HttpResponseHeader header = (HttpResponseHeader)headers[i]; headerElements.Add(new HeaderElement(header.Name, header.Value)); } List <ResponseElement> responseElements = null; ArrayList buffers = cachedRawResponse._rawResponse.Buffers; capacity = (buffers != null) ? buffers.Count : 0; for (int j = 0; j < capacity; j++) { if (responseElements == null) { responseElements = new List <ResponseElement>(capacity); } IHttpResponseElement element = buffers[j] as IHttpResponseElement; if (element is HttpFileResponseElement) { HttpFileResponseElement element2 = element as HttpFileResponseElement; responseElements.Add(new FileResponseElement(element2.FileName, element2.Offset, element.GetSize())); } else if (element is HttpSubstBlockResponseElement) { HttpSubstBlockResponseElement element3 = element as HttpSubstBlockResponseElement; responseElements.Add(new SubstitutionResponseElement(element3.Callback)); } else { byte[] bytes = element.GetBytes(); long length = (bytes != null) ? ((long)bytes.Length) : ((long)0); responseElements.Add(new MemoryResponseElement(bytes, length)); } } return(new OutputCacheEntry(cachedRawResponse._cachedVaryId, cachedRawResponse._settings, cachedRawResponse._kernelCacheUrl, depKey, fileDependencies, cachedRawResponse._rawResponse.StatusCode, cachedRawResponse._rawResponse.StatusDescription, headerElements, responseElements)); }
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); }