internal void WriteSubstBlock(HttpResponseSubstitutionCallback callback, IIS7WorkerRequest iis7WorkerRequest) { if (this._charBufferLength != this._charBufferFree) { this.FlushCharBuffer(true); } this._lastBuffer = null; IHttpResponseElement element = new HttpSubstBlockResponseElement(callback, this.Encoding, this.Encoder, iis7WorkerRequest); this._buffers.Add(element); if (iis7WorkerRequest != null) { this.SubstElements.Add(element); } if (!this._responseBufferingOn) { this._response.Flush(); } }
internal void UseSnapshot(ArrayList buffers) { this.ClearBuffers(); int count = buffers.Count; for (int i = 0; i < count; i++) { object obj2 = buffers[i]; HttpSubstBlockResponseElement element = obj2 as HttpSubstBlockResponseElement; if (element != null) { this._buffers.Add(element.Substitute(this.Encoding)); } else { this._buffers.Add(obj2); } } }
internal int FindSubstitutionBlock(String name) { int n = _buffers.Count; for (int i = 0; i < n; i++) { // find the substitution block by name IHttpResponseElement element = (IHttpResponseElement)_buffers[i]; if (element is HttpSubstBlockResponseElement) { HttpSubstBlockResponseElement block = (HttpSubstBlockResponseElement)element; if (String.Compare(block.Name, name, true, CultureInfo.InvariantCulture) == 0) { return(i); } } } return(-1); }
internal void MakeSubstitution(String name, String value, bool canChangeSize) { // find the block by name int i = FindSubstitutionBlock(name); if (i < 0) { return; } HttpSubstBlockResponseElement block = (HttpSubstBlockResponseElement)_buffers[i]; // allocate byte array int size = block.GetSize(); int maxBytes = _responseEncoding.GetMaxByteCount(value.Length); if (maxBytes < size) { maxBytes = size; } byte[] bytes = new byte[maxBytes]; // prefill with filler System.Array.Copy(block.Data, bytes, size); // convert string int newSize = _responseEncoder.GetBytes(value.ToCharArray(), 0, value.Length, bytes, 0, true); // adjust size if allowed if (canChangeSize) { size = newSize; } // replace substitution block with memory block _buffers[i] = new HttpResponseBufferElement(bytes, size); }
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; }
// // Support for substitution blocks // internal void WriteSubstBlock(HttpResponseSubstitutionCallback callback, IIS7WorkerRequest iis7WorkerRequest) { if (_charBufferLength != _charBufferFree) FlushCharBuffer(true); _lastBuffer = null; // add new substitution block to the buffer list IHttpResponseElement element = new HttpSubstBlockResponseElement(callback, Encoding, Encoder, iis7WorkerRequest); _buffers.Add(element); if (iis7WorkerRequest != null) { SubstElements.Add(element); } if (!_responseBufferingOn) _response.Flush(); }
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); }