Beispiel #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;
             }
         }
     }
 }
Beispiel #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);
        }
        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;
            }
        }
Beispiel #4
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;
                 }
             }
         }
     }
 }
Beispiel #5
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));
        }