Exemplo n.º 1
0
 internal void FilterIntegrated(bool finalFiltering, IIS7WorkerRequest wr)
 {
     if (this._installedFilter != null)
     {
         if (this._charBufferLength != this._charBufferFree)
         {
             this.FlushCharBuffer(true);
         }
         this._lastBuffer = null;
         ArrayList list = this._buffers;
         this._buffers = new ArrayList();
         ArrayList list2          = null;
         bool      hasSubstBlocks = false;
         list2 = wr.GetBufferedResponseChunks(false, null, ref hasSubstBlocks);
         this._filterSink.Filtering = true;
         try
         {
             if (list2 != null)
             {
                 for (int i = 0; i < list2.Count; i++)
                 {
                     IHttpResponseElement element = (IHttpResponseElement)list2[i];
                     long size = element.GetSize();
                     if (size > 0L)
                     {
                         this._installedFilter.Write(element.GetBytes(), 0, Convert.ToInt32(size));
                     }
                 }
                 wr.ClearResponse(true, false);
             }
             if (list != null)
             {
                 for (int j = 0; j < list.Count; j++)
                 {
                     IHttpResponseElement element2 = (IHttpResponseElement)list[j];
                     long num4 = element2.GetSize();
                     if (num4 > 0L)
                     {
                         this._installedFilter.Write(element2.GetBytes(), 0, Convert.ToInt32(num4));
                     }
                 }
             }
             this._installedFilter.Flush();
         }
         finally
         {
             try
             {
                 if (finalFiltering)
                 {
                     this._installedFilter.Close();
                 }
             }
             finally
             {
                 this._filterSink.Filtering = false;
             }
         }
     }
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        internal void Filter(bool finalFiltering)
        {
            // no filter?
            if (_installedFilter == null)
            {
                return;
            }

            // flush char buffer and remember old buffers
            if (_charBufferLength != _charBufferFree)
            {
                FlushCharBuffer(true);
            }

            _lastBuffer = null;

            // no content to filter
            if (_buffers.Count == 0)
            {
                return;
            }

            // remember old buffers
            ArrayList oldBuffers = _buffers;

            _buffers = new ArrayList();

            // push old buffer list through the filter

            Debug.Assert(_filterSink != null);

            _filterSink.Filtering = true;

            try {
                int n = oldBuffers.Count;
                for (int i = 0; i < n; i++)
                {
                    IHttpResponseElement buf = (IHttpResponseElement)oldBuffers[i];

                    int len = buf.GetSize();

                    if (len > 0)
                    {
                        _installedFilter.Write(buf.GetBytes(), 0, len);
                    }
                }

                _installedFilter.Flush();

                if (finalFiltering)
                {
                    _installedFilter.Close();
                }
            }
            finally {
                _filterSink.Filtering = false;
            }
        }
Exemplo n.º 4
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 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));
        }
Exemplo n.º 5
0
 internal void Filter(bool finalFiltering)
 {
     if (this._installedFilter != null)
     {
         if (this._charBufferLength != this._charBufferFree)
         {
             this.FlushCharBuffer(true);
         }
         this._lastBuffer = null;
         if ((this._buffers.Count != 0) || finalFiltering)
         {
             ArrayList list = this._buffers;
             this._buffers = new ArrayList();
             this._filterSink.Filtering = true;
             try
             {
                 int count = list.Count;
                 for (int i = 0; i < count; i++)
                 {
                     IHttpResponseElement element = (IHttpResponseElement)list[i];
                     long size = element.GetSize();
                     if (size > 0L)
                     {
                         this._installedFilter.Write(element.GetBytes(), 0, Convert.ToInt32(size));
                     }
                 }
                 this._installedFilter.Flush();
             }
             finally
             {
                 try
                 {
                     if (finalFiltering)
                     {
                         this._installedFilter.Close();
                     }
                 }
                 finally
                 {
                     this._filterSink.Filtering = false;
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        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));
        }
 internal HttpSubstBlockResponseElement(HttpResponseSubstitutionCallback callback, Encoding encoding, System.Text.Encoder encoder, IIS7WorkerRequest iis7WorkerRequest)
 {
     this._callback = callback;
     if (iis7WorkerRequest != null)
     {
         this._isIIS7WorkerRequest = true;
         string s = this._callback(HttpContext.Current);
         if (s == null)
         {
             throw new ArgumentNullException("substitutionString");
         }
         this.CreateFirstSubstData(s, iis7WorkerRequest, encoder);
     }
     else
     {
         this._firstSubstitution = this.Substitute(encoding);
     }
 }
Exemplo n.º 8
0
 internal HttpSubstBlockResponseElement(HttpResponseSubstitutionCallback callback, Encoding encoding, System.Text.Encoder encoder, IIS7WorkerRequest iis7WorkerRequest)
 {
     this._callback = callback;
     if (iis7WorkerRequest != null)
     {
         this._isIIS7WorkerRequest = true;
         string s = this._callback(HttpContext.Current);
         if (s == null)
         {
             throw new ArgumentNullException("substitutionString");
         }
         this.CreateFirstSubstData(s, iis7WorkerRequest, encoder);
     }
     else
     {
         this._firstSubstitution = this.Substitute(encoding);
     }
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
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);
        }