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);
 }
Exemple #2
0
 internal void Reset()
 {
     this._varyByContentEncodings.Reset();
     this._varyByHeaders.Reset();
     this._varyByParams.Reset();
     this._isModified          = false;
     this._hasSetCookieHeader  = false;
     this._noServerCaching     = false;
     this._cacheExtension      = null;
     this._noTransforms        = false;
     this._ignoreRangeRequests = false;
     this._varyByCustom        = null;
     this._cacheability        = HttpCacheability.Public | HttpCacheability.Private;
     this._noStore             = false;
     this._privateFields       = null;
     this._noCacheFields       = null;
     this._utcExpires          = DateTime.MinValue;
     this._isExpiresSet        = false;
     this._maxAge              = TimeSpan.Zero;
     this._isMaxAgeSet         = false;
     this._proxyMaxAge         = TimeSpan.Zero;
     this._isProxyMaxAgeSet    = false;
     this._slidingExpiration   = -1;
     this._slidingDelta        = TimeSpan.Zero;
     this._utcTimestampCreated = DateTime.MinValue;
     this._utcTimestampRequest = DateTime.MinValue;
     this._validUntilExpires   = -1;
     this._allowInHistory      = -1;
     this._revalidation        = HttpCacheRevalidation.None;
     this._utcLastModified     = DateTime.MinValue;
     this._isLastModifiedSet   = false;
     this._etag = null;
     this._generateLastModifiedFromFiles = false;
     this._generateEtagFromFiles         = false;
     this._validationCallbackInfo        = null;
     this._useCachedHeaders            = false;
     this._headerCacheControl          = null;
     this._headerPragma                = null;
     this._headerExpires               = null;
     this._headerLastModified          = null;
     this._headerEtag                  = null;
     this._headerVaryBy                = null;
     this._noMaxAgeInCacheControl      = false;
     this._hasUserProvidedDependencies = false;
     this._omitVaryStar                = -1;
 }
 internal HttpCachePolicySettings(bool isModified, System.Web.ValidationCallbackInfo[] validationCallbackInfo, bool hasSetCookieHeader, bool noServerCaching, string cacheExtension, bool noTransforms, bool ignoreRangeRequests, string[] varyByContentEncodings, string[] varyByHeaderValues, string[] varyByParamValues, string varyByCustom, HttpCacheability cacheability, bool noStore, string[] privateFields, string[] noCacheFields, DateTime utcExpires, bool isExpiresSet, TimeSpan maxAge, bool isMaxAgeSet, TimeSpan proxyMaxAge, bool isProxyMaxAgeSet, int slidingExpiration, TimeSpan slidingDelta, DateTime utcTimestampCreated, int validUntilExpires, int allowInHistory, HttpCacheRevalidation revalidation, DateTime utcLastModified, bool isLastModifiedSet, string etag, bool generateLastModifiedFromFiles, bool generateEtagFromFiles, int omitVaryStar, HttpResponseHeader headerCacheControl, HttpResponseHeader headerPragma, HttpResponseHeader headerExpires, HttpResponseHeader headerLastModified, HttpResponseHeader headerEtag, HttpResponseHeader headerVaryBy, bool hasUserProvidedDependencies)
 {
     this._isModified             = isModified;
     this._validationCallbackInfo = validationCallbackInfo;
     this._hasSetCookieHeader     = hasSetCookieHeader;
     this._noServerCaching        = noServerCaching;
     this._cacheExtension         = cacheExtension;
     this._noTransforms           = noTransforms;
     this._ignoreRangeRequests    = ignoreRangeRequests;
     this._varyByContentEncodings = varyByContentEncodings;
     this._varyByHeaderValues     = varyByHeaderValues;
     this._varyByParamValues      = varyByParamValues;
     this._varyByCustom           = varyByCustom;
     this._cacheability           = cacheability;
     this._noStore             = noStore;
     this._privateFields       = privateFields;
     this._noCacheFields       = noCacheFields;
     this._utcExpires          = utcExpires;
     this._isExpiresSet        = isExpiresSet;
     this._maxAge              = maxAge;
     this._isMaxAgeSet         = isMaxAgeSet;
     this._proxyMaxAge         = proxyMaxAge;
     this._isProxyMaxAgeSet    = isProxyMaxAgeSet;
     this._slidingExpiration   = slidingExpiration;
     this._slidingDelta        = slidingDelta;
     this._utcTimestampCreated = utcTimestampCreated;
     this._validUntilExpires   = validUntilExpires;
     this._allowInHistory      = allowInHistory;
     this._revalidation        = revalidation;
     this._utcLastModified     = utcLastModified;
     this._isLastModifiedSet   = isLastModifiedSet;
     this._etag = etag;
     this._generateLastModifiedFromFiles = generateLastModifiedFromFiles;
     this._generateEtagFromFiles         = generateEtagFromFiles;
     this._omitVaryStar                = omitVaryStar;
     this._headerCacheControl          = headerCacheControl;
     this._headerPragma                = headerPragma;
     this._headerExpires               = headerExpires;
     this._headerLastModified          = headerLastModified;
     this._headerEtag                  = headerEtag;
     this._headerVaryBy                = headerVaryBy;
     this._hasUserProvidedDependencies = hasUserProvidedDependencies;
 }
 internal HttpCachePolicySettings(bool isModified, System.Web.ValidationCallbackInfo[] validationCallbackInfo, bool hasSetCookieHeader, bool noServerCaching, string cacheExtension, bool noTransforms, bool ignoreRangeRequests, string[] varyByContentEncodings, string[] varyByHeaderValues, string[] varyByParamValues, string varyByCustom, HttpCacheability cacheability, bool noStore, string[] privateFields, string[] noCacheFields, DateTime utcExpires, bool isExpiresSet, TimeSpan maxAge, bool isMaxAgeSet, TimeSpan proxyMaxAge, bool isProxyMaxAgeSet, int slidingExpiration, TimeSpan slidingDelta, DateTime utcTimestampCreated, int validUntilExpires, int allowInHistory, HttpCacheRevalidation revalidation, DateTime utcLastModified, bool isLastModifiedSet, string etag, bool generateLastModifiedFromFiles, bool generateEtagFromFiles, int omitVaryStar, HttpResponseHeader headerCacheControl, HttpResponseHeader headerPragma, HttpResponseHeader headerExpires, HttpResponseHeader headerLastModified, HttpResponseHeader headerEtag, HttpResponseHeader headerVaryBy, bool hasUserProvidedDependencies)
 {
     this._isModified = isModified;
     this._validationCallbackInfo = validationCallbackInfo;
     this._hasSetCookieHeader = hasSetCookieHeader;
     this._noServerCaching = noServerCaching;
     this._cacheExtension = cacheExtension;
     this._noTransforms = noTransforms;
     this._ignoreRangeRequests = ignoreRangeRequests;
     this._varyByContentEncodings = varyByContentEncodings;
     this._varyByHeaderValues = varyByHeaderValues;
     this._varyByParamValues = varyByParamValues;
     this._varyByCustom = varyByCustom;
     this._cacheability = cacheability;
     this._noStore = noStore;
     this._privateFields = privateFields;
     this._noCacheFields = noCacheFields;
     this._utcExpires = utcExpires;
     this._isExpiresSet = isExpiresSet;
     this._maxAge = maxAge;
     this._isMaxAgeSet = isMaxAgeSet;
     this._proxyMaxAge = proxyMaxAge;
     this._isProxyMaxAgeSet = isProxyMaxAgeSet;
     this._slidingExpiration = slidingExpiration;
     this._slidingDelta = slidingDelta;
     this._utcTimestampCreated = utcTimestampCreated;
     this._validUntilExpires = validUntilExpires;
     this._allowInHistory = allowInHistory;
     this._revalidation = revalidation;
     this._utcLastModified = utcLastModified;
     this._isLastModifiedSet = isLastModifiedSet;
     this._etag = etag;
     this._generateLastModifiedFromFiles = generateLastModifiedFromFiles;
     this._generateEtagFromFiles = generateEtagFromFiles;
     this._omitVaryStar = omitVaryStar;
     this._headerCacheControl = headerCacheControl;
     this._headerPragma = headerPragma;
     this._headerExpires = headerExpires;
     this._headerLastModified = headerLastModified;
     this._headerEtag = headerEtag;
     this._headerVaryBy = headerVaryBy;
     this._hasUserProvidedDependencies = hasUserProvidedDependencies;
 }
 public string HeaderValueFor(HttpResponseHeader key)
 {
     return HeaderValueFor(HttpResponseHeaders.HeaderNameFor(key));
 }
Exemple #6
0
        /*  InitRequest
         *  Initialize the given dataset with basic
         *  request information
         */
        private void InitRequest()
        {
            // Master request is assumed to be initialized first
            System.Web.Util.Debug.Assert(_masterRequest != null);

            DataSet requestData = _masterRequest.Clone();

            // request info
            DataRow row = NewRow(requestData, SR.Trace_Request);

            row[SR.Trace_Time_of_Request] = _context.Timestamp.ToString("G");

            string url = _context.Request.RawUrl;
            int    loc = url.IndexOf("?", StringComparison.Ordinal);

            if (loc != -1)
            {
                url = url.Substring(0, loc);
            }
            row[SR.Trace_Url] = url;

            row[SR.Trace_Request_Type] = _context.Request.HttpMethod;
            try {
                row[SR.Trace_Request_Encoding] = _context.Request.ContentEncoding.EncodingName;
            }
            catch {
                // if we get an exception getting the ContentEncoding, most likely
                // there's an error in the config file.  Just ignore it so we can finish InitRequest.
            }

            if (TraceMode == TraceMode.SortByCategory)
            {
                requestData.Tables[SR.Trace_Trace_Information].DefaultView.Sort = SR.Trace_Category;
            }
            AddRow(requestData, SR.Trace_Request, row);

            // header info
            try {
                //

                AddCollectionToRequestData(requestData, SR.Trace_Headers_Collection, _context.Request.Unvalidated.Headers);
            }
            catch {
                // ---- exceptions when we fail to get the unvalidated collection
            }

            // response header info
            ArrayList headers = _context.Response.GenerateResponseHeaders(false);
            int       n       = (headers != null) ? headers.Count : 0;

            for (int i = 0; i < n; i++)
            {
                HttpResponseHeader h = (HttpResponseHeader)headers[i];
                row = NewRow(requestData, SR.Trace_Response_Headers_Collection);
                row[SR.Trace_Name]  = h.Name;
                row[SR.Trace_Value] = h.Value;
                AddRow(requestData, SR.Trace_Response_Headers_Collection, row);
            }

            //form info
            try {
                AddCollectionToRequestData(requestData, SR.Trace_Form_Collection, _context.Request.Unvalidated.Form);
            }
            catch {
                // ---- exceptions when we fail to get the unvalidated collection
            }

            //QueryString info
            try {
                AddCollectionToRequestData(requestData, SR.Trace_Querystring_Collection, _context.Request.Unvalidated.QueryString);
            }
            catch {
                // ---- exceptions when we fail to get the unvalidated collection
            }

            //Server Variable info
            if (HttpRuntime.HasAppPathDiscoveryPermission())
            {
                AddCollectionToRequestData(requestData, SR.Trace_Server_Variables, _context.Request.ServerVariables);
            }

            _requestData = requestData;

            if (HttpRuntime.UseIntegratedPipeline)
            {
                // Dev10 914119: When trace is enabled, the request entity is read and no longer
                // available to IIS.  In integrated mode, we have an API that allows us to reinsert
                // the entity.  Although it is expensive, performance is not a concern when
                // trace is enalbed, so we will reinsert just in case a native handler needs
                // to access the entity.  I decided not to check the current handler, since
                // that can be changed if someone sets the IIS script map.
                _context.Request.InsertEntityBody();
            }
        }
        private void InitRequest()
        {
            int     num2;
            DataSet ds  = _masterRequest.Clone();
            DataRow row = this.NewRow(ds, "Trace_Request");

            row["Trace_Time_of_Request"] = this._context.Timestamp.ToString("G");
            string rawUrl = this._context.Request.RawUrl;
            int    index  = rawUrl.IndexOf("?", StringComparison.Ordinal);

            if (index != -1)
            {
                rawUrl = rawUrl.Substring(0, index);
            }
            row["Trace_Url"]          = rawUrl;
            row["Trace_Request_Type"] = this._context.Request.HttpMethod;
            try
            {
                row["Trace_Request_Encoding"] = this._context.Request.ContentEncoding.EncodingName;
            }
            catch
            {
            }
            if (this.TraceMode == System.Web.TraceMode.SortByCategory)
            {
                ds.Tables["Trace_Trace_Information"].DefaultView.Sort = "Trace_Category";
            }
            this.AddRow(ds, "Trace_Request", row);
            string[] allKeys = this._context.Request.Headers.AllKeys;
            for (num2 = 0; num2 < allKeys.Length; num2++)
            {
                row = this.NewRow(ds, "Trace_Headers_Collection");
                row["Trace_Name"]  = allKeys[num2];
                row["Trace_Value"] = this._context.Request.Headers[allKeys[num2]];
                this.AddRow(ds, "Trace_Headers_Collection", row);
            }
            ArrayList list = this._context.Response.GenerateResponseHeaders(false);
            int       num3 = (list != null) ? list.Count : 0;

            for (num2 = 0; num2 < num3; num2++)
            {
                HttpResponseHeader header = (HttpResponseHeader)list[num2];
                row = this.NewRow(ds, "Trace_Response_Headers_Collection");
                row["Trace_Name"]  = header.Name;
                row["Trace_Value"] = header.Value;
                this.AddRow(ds, "Trace_Response_Headers_Collection", row);
            }
            allKeys = this._context.Request.Form.AllKeys;
            for (num2 = 0; num2 < allKeys.Length; num2++)
            {
                row = this.NewRow(ds, "Trace_Form_Collection");
                row["Trace_Name"]  = allKeys[num2];
                row["Trace_Value"] = this._context.Request.Form[allKeys[num2]];
                this.AddRow(ds, "Trace_Form_Collection", row);
            }
            allKeys = this._context.Request.QueryString.AllKeys;
            for (num2 = 0; num2 < allKeys.Length; num2++)
            {
                row = this.NewRow(ds, "Trace_Querystring_Collection");
                row["Trace_Name"]  = allKeys[num2];
                row["Trace_Value"] = this._context.Request.QueryString[allKeys[num2]];
                this.AddRow(ds, "Trace_Querystring_Collection", row);
            }
            if (HttpRuntime.HasAppPathDiscoveryPermission())
            {
                allKeys = this._context.Request.ServerVariables.AllKeys;
                for (num2 = 0; num2 < allKeys.Length; num2++)
                {
                    row = this.NewRow(ds, "Trace_Server_Variables");
                    row["Trace_Name"]  = allKeys[num2];
                    row["Trace_Value"] = this._context.Request.ServerVariables.Get(allKeys[num2]);
                    this.AddRow(ds, "Trace_Server_Variables", row);
                }
            }
            this._requestData = ds;
        }
        void UpdateCachedHeaders(HttpResponse response) {
            StringBuilder       sb;
            HttpCacheability    cacheability;
            int                 i, n;
            String              expirationDate;           
            String              lastModifiedDate;         
            String              varyByHeaders;            
            bool                omitVaryStar;

            if (_useCachedHeaders) {
                return;
            }

            Debug.Assert((_utcTimestampCreated == DateTime.MinValue && _utcTimestampRequest == DateTime.MinValue) ||
                         (_utcTimestampCreated != DateTime.MinValue && _utcTimestampRequest != DateTime.MinValue),
                        "_utcTimestampCreated and _utcTimestampRequest are out of [....] in UpdateCachedHeaders");

            if (_utcTimestampCreated == DateTime.MinValue) {
                _utcTimestampCreated = _utcTimestampRequest = response.Context.UtcTimestamp;
            }

            if (_slidingExpiration != 1) {
                _slidingDelta = TimeSpan.Zero;
            }
            else if (_isMaxAgeSet) {
                _slidingDelta = _maxAge;
            }
            else if (_isExpiresSet) {
                _slidingDelta = _utcExpires - _utcTimestampCreated;
            }
            else {
                _slidingDelta = TimeSpan.Zero;
            }

            _headerCacheControl = null;
            _headerPragma = null;      
            _headerExpires = null;     
            _headerLastModified = null;
            _headerEtag = null;        
            _headerVaryBy = null;      

            UpdateFromDependencies(response);

            /*
             * Cache control header
             */
            sb = new StringBuilder();

            if (_cacheability == (HttpCacheability) (int) HttpCacheabilityLimits.None) {
                cacheability = HttpCacheability.Private;
            }
            else {
                cacheability = _cacheability;
            }

            AppendValueToHeader(sb, s_cacheabilityTokens[(int) cacheability]);

            if (cacheability == HttpCacheability.Public && _privateFields != null) {
                Debug.Assert(_privateFields.Size > 0);

                AppendValueToHeader(sb, "private=\"");
                sb.Append(_privateFields.GetKey(0));
                for (i = 1, n = _privateFields.Size; i < n; i++) {
                    AppendValueToHeader(sb, _privateFields.GetKey(i));
                }

                sb.Append('\"');
            }

            if (    cacheability != HttpCacheability.NoCache &&
                    cacheability != HttpCacheability.ServerAndNoCache && 
                    _noCacheFields != null) {

                Debug.Assert(_noCacheFields.Size > 0);

                AppendValueToHeader(sb, "no-cache=\"");
                sb.Append(_noCacheFields.GetKey(0));
                for (i = 1, n = _noCacheFields.Size; i < n; i++) {
                    AppendValueToHeader(sb, _noCacheFields.GetKey(i));
                }

                sb.Append('\"');
            }

            if (_noStore) {
                AppendValueToHeader(sb, "no-store");
            }

            AppendValueToHeader(sb, s_revalidationTokens[(int)_revalidation]);

            if (_noTransforms) {
                AppendValueToHeader(sb, "no-transform");
            }

            if (_cacheExtension != null) {
                AppendValueToHeader(sb, _cacheExtension);
            }


            /*
             * don't send expiration information when item shouldn't be cached
             * for cached header, only add max-age when it doesn't change
             * based on the time requested
             */
            if (      _slidingExpiration == 1                 
                 &&   cacheability != HttpCacheability.NoCache
                 &&   cacheability != HttpCacheability.ServerAndNoCache) {
                
                if (_isMaxAgeSet && !_noMaxAgeInCacheControl) {
                    AppendValueToHeader(sb, "max-age=" + ((long)_maxAge.TotalSeconds).ToString(CultureInfo.InvariantCulture));
                }
    
                if (_isProxyMaxAgeSet && !_noMaxAgeInCacheControl) {
                    AppendValueToHeader(sb, "s-maxage=" + ((long)(_proxyMaxAge).TotalSeconds).ToString(CultureInfo.InvariantCulture));
                }
            }

            if (sb.Length > 0) {
                _headerCacheControl = new HttpResponseHeader(HttpWorkerRequest.HeaderCacheControl, sb.ToString());
            }

            /*
             * Pragma: no-cache and Expires: -1
             */
            if (cacheability == HttpCacheability.NoCache || cacheability == HttpCacheability.ServerAndNoCache) {
                if (s_headerPragmaNoCache == null) {
                    s_headerPragmaNoCache = new HttpResponseHeader(HttpWorkerRequest.HeaderPragma, "no-cache");
                }

                _headerPragma = s_headerPragmaNoCache;

                if (_allowInHistory != 1) {
                    if (s_headerExpiresMinus1 == null) {
                        s_headerExpiresMinus1 = new HttpResponseHeader(HttpWorkerRequest.HeaderExpires, "-1");
                    }

                    _headerExpires = s_headerExpiresMinus1;
                }
            }
            else {
                /*
                 * Expires header.
                 */
                if (_isExpiresSet && _slidingExpiration != 1) {
                    expirationDate = HttpUtility.FormatHttpDateTimeUtc(_utcExpires);
                    _headerExpires = new HttpResponseHeader(HttpWorkerRequest.HeaderExpires, expirationDate);
                }

                /*
                 * Last Modified header.
                 */
                if (_isLastModifiedSet) {
                    lastModifiedDate = HttpUtility.FormatHttpDateTimeUtc(_utcLastModified);
                    _headerLastModified = new HttpResponseHeader(HttpWorkerRequest.HeaderLastModified, lastModifiedDate);
                }


                if (cacheability != HttpCacheability.Private) {
                    /*
                     * Etag.
                     */
                    if (_etag != null) {
                        _headerEtag = new HttpResponseHeader(HttpWorkerRequest.HeaderEtag, _etag);
                    }

                    /*
                     * Vary
                     */
                    varyByHeaders = null;

                    // automatic VaryStar processing
                    // See if anyone has explicitly set this value
                    if (_omitVaryStar != -1) {
                        omitVaryStar = _omitVaryStar == 1 ? true : false;
                    }
                    else {
                        // If no one has set this value, go with the default from config
                        RuntimeConfig config = RuntimeConfig.GetLKGConfig(response.Context);
                        OutputCacheSection outputCacheConfig = config.OutputCache;
                        if (outputCacheConfig != null) {
                            omitVaryStar = outputCacheConfig.OmitVaryStar;
                        }
                        else {
                            omitVaryStar = OutputCacheSection.DefaultOmitVaryStar;
                        }
                    }
                    
                    if (!omitVaryStar) {
                        // Dev10 Bug 425047 - OutputCache Location="ServerAndClient" (HttpCacheability.ServerAndPrivate) should 
                        // not use "Vary: *" so the response can be cached on the client
                        if (_varyByCustom != null || (_varyByParams.IsModified() && !_varyByParams.IgnoreParams)) {
                            varyByHeaders = "*";
                        }
                    }

                    if (varyByHeaders == null) {
                       varyByHeaders = _varyByHeaders.ToHeaderString();
                    }

                    if (varyByHeaders != null) {
                       _headerVaryBy = new HttpResponseHeader(HttpWorkerRequest.HeaderVary, varyByHeaders);
                    }
                }
            }

            _useCachedHeaders = true;
        }
        /*
         * Restore original values
         */
        internal void Reset() {
            _varyByContentEncodings.Reset();
            _varyByHeaders.Reset();
            _varyByParams.Reset();

            _isModified = false;
            _hasSetCookieHeader = false;
            _noServerCaching = false;
            _cacheExtension = null;
            _noTransforms = false;
            _ignoreRangeRequests = false;
            _varyByCustom = null;
            _cacheability = (HttpCacheability) (int) HttpCacheabilityLimits.None;
            _noStore = false;
            _privateFields = null;
            _noCacheFields = null;
            _utcExpires = DateTime.MinValue;
            _isExpiresSet = false;
            _maxAge = TimeSpan.Zero;
            _isMaxAgeSet = false;
            _proxyMaxAge = TimeSpan.Zero;
            _isProxyMaxAgeSet = false;
            _slidingExpiration = -1;
            _slidingDelta = TimeSpan.Zero;
            _utcTimestampCreated = DateTime.MinValue;
            _utcTimestampRequest = DateTime.MinValue;
            _validUntilExpires = -1;
            _allowInHistory = -1;
            _revalidation = HttpCacheRevalidation.None;
            _utcLastModified = DateTime.MinValue;
            _isLastModifiedSet = false;
            _etag = null;

            _generateLastModifiedFromFiles = false; 
            _generateEtagFromFiles = false;         
            _validationCallbackInfo = null;       
        
            _useCachedHeaders = false;
            _headerCacheControl = null;
            _headerPragma = null;        
            _headerExpires = null;       
            _headerLastModified = null;  
            _headerEtag = null;          
            _headerVaryBy = null;       

            _noMaxAgeInCacheControl = false;

            _hasUserProvidedDependencies = false;

            _omitVaryStar = -1;
        }
        //
        // Private helper methods
        //

        private void AppendHeader(HttpResponseHeader h) {
            if (_customHeaders == null)
                _customHeaders = new ArrayList();
            _customHeaders.Add(h);
            if (_cachePolicy != null && StringUtil.EqualsIgnoreCase("Set-Cookie", h.Name)) {
                _cachePolicy.SetHasSetCookieHeader();
            }
        }
        //
        // Public methods
        //

        /*
          * Add Http custom header
          *
          * @param name header name
          * @param value header value
          */

        /// <devdoc>
        ///    <para>Adds an HTTP
        ///       header to the output stream.</para>
        /// </devdoc>
        public void AppendHeader(String name, String value) {
            bool isCacheHeader = false;

            if (_headersWritten)
                throw new HttpException(SR.GetString(SR.Cannot_append_header_after_headers_sent));

            // some headers are stored separately or require special action
            int knownHeaderIndex = HttpWorkerRequest.GetKnownResponseHeaderIndex(name);

            switch (knownHeaderIndex) {
                case HttpWorkerRequest.HeaderContentType:
                    ContentType = value;
                    return; // don't keep as custom header

                case HttpWorkerRequest.HeaderContentLength:
                    _contentLengthSet = true;
                    break;

                case HttpWorkerRequest.HeaderLocation:
                    RedirectLocation = value;
                    return; // don't keep as custom header

                case HttpWorkerRequest.HeaderTransferEncoding:
                    _transferEncodingSet = true;
                    break;

                case HttpWorkerRequest.HeaderCacheControl:
                    _cacheControlHeaderAdded = true;
                    goto case HttpWorkerRequest.HeaderExpires;
                case HttpWorkerRequest.HeaderExpires:
                case HttpWorkerRequest.HeaderLastModified:
                case HttpWorkerRequest.HeaderEtag:
                case HttpWorkerRequest.HeaderVary:
                    isCacheHeader = true;
                    break;
            }

            // In integrated mode, write the headers directly
            if (_wr is IIS7WorkerRequest) {
                Headers.Add(name, value);
            }
            else {
                if (isCacheHeader)
                {
                    // don't keep as custom header
                    if (_cacheHeaders == null) {
                        _cacheHeaders = new ArrayList();
                    }

                    _cacheHeaders.Add(new HttpResponseHeader(knownHeaderIndex, value));
                    return;
                }
                else {
                    HttpResponseHeader h;
                    if (knownHeaderIndex >= 0)
                        h = new HttpResponseHeader(knownHeaderIndex, value);
                    else
                        h = new HttpResponseHeader(name, value);

                    AppendHeader(h);
                }
            }
        }
Exemple #12
0
        private void UpdateCachedHeaders(HttpResponse response)
        {
            if (!this._useCachedHeaders)
            {
                HttpCacheability @private;
                int num;
                int size;
                if (this._utcTimestampCreated == DateTime.MinValue)
                {
                    this._utcTimestampCreated = this._utcTimestampRequest = response.Context.UtcTimestamp;
                }
                if (this._slidingExpiration != 1)
                {
                    this._slidingDelta = TimeSpan.Zero;
                }
                else if (this._isMaxAgeSet)
                {
                    this._slidingDelta = this._maxAge;
                }
                else if (this._isExpiresSet)
                {
                    this._slidingDelta = (TimeSpan)(this._utcExpires - this._utcTimestampCreated);
                }
                else
                {
                    this._slidingDelta = TimeSpan.Zero;
                }
                this._headerCacheControl = null;
                this._headerPragma       = null;
                this._headerExpires      = null;
                this._headerLastModified = null;
                this._headerEtag         = null;
                this._headerVaryBy       = null;
                this.UpdateFromDependencies(response);
                StringBuilder s = new StringBuilder();
                if (this._cacheability == (HttpCacheability.Public | HttpCacheability.Private))
                {
                    @private = HttpCacheability.Private;
                }
                else
                {
                    @private = this._cacheability;
                }
                AppendValueToHeader(s, s_cacheabilityTokens[(int)@private]);
                if ((@private == HttpCacheability.Public) && (this._privateFields != null))
                {
                    AppendValueToHeader(s, "private=\"");
                    s.Append(this._privateFields.GetKey(0));
                    num  = 1;
                    size = this._privateFields.Size;
                    while (num < size)
                    {
                        AppendValueToHeader(s, this._privateFields.GetKey(num));
                        num++;
                    }
                    s.Append('"');
                }
                if (((@private != HttpCacheability.NoCache) && (@private != HttpCacheability.Server)) && (this._noCacheFields != null))
                {
                    AppendValueToHeader(s, "no-cache=\"");
                    s.Append(this._noCacheFields.GetKey(0));
                    num  = 1;
                    size = this._noCacheFields.Size;
                    while (num < size)
                    {
                        AppendValueToHeader(s, this._noCacheFields.GetKey(num));
                        num++;
                    }
                    s.Append('"');
                }
                if (this._noStore)
                {
                    AppendValueToHeader(s, "no-store");
                }
                AppendValueToHeader(s, s_revalidationTokens[(int)this._revalidation]);
                if (this._noTransforms)
                {
                    AppendValueToHeader(s, "no-transform");
                }
                if (this._cacheExtension != null)
                {
                    AppendValueToHeader(s, this._cacheExtension);
                }
                if (((this._slidingExpiration == 1) && (@private != HttpCacheability.NoCache)) && (@private != HttpCacheability.Server))
                {
                    if (this._isMaxAgeSet && !this._noMaxAgeInCacheControl)
                    {
                        AppendValueToHeader(s, "max-age=" + ((long)this._maxAge.TotalSeconds).ToString(CultureInfo.InvariantCulture));
                    }
                    if (this._isProxyMaxAgeSet && !this._noMaxAgeInCacheControl)
                    {
                        AppendValueToHeader(s, "s-maxage=" + ((long)this._proxyMaxAge.TotalSeconds).ToString(CultureInfo.InvariantCulture));
                    }
                }
                if (s.Length > 0)
                {
                    this._headerCacheControl = new HttpResponseHeader(0, s.ToString());
                }
                switch (@private)
                {
                case HttpCacheability.NoCache:
                case HttpCacheability.Server:
                    if (s_headerPragmaNoCache == null)
                    {
                        s_headerPragmaNoCache = new HttpResponseHeader(4, "no-cache");
                    }
                    this._headerPragma = s_headerPragmaNoCache;
                    if (this._allowInHistory != 1)
                    {
                        if (s_headerExpiresMinus1 == null)
                        {
                            s_headerExpiresMinus1 = new HttpResponseHeader(0x12, "-1");
                        }
                        this._headerExpires = s_headerExpiresMinus1;
                    }
                    break;

                default:
                    if (this._isExpiresSet && (this._slidingExpiration != 1))
                    {
                        string str = HttpUtility.FormatHttpDateTimeUtc(this._utcExpires);
                        this._headerExpires = new HttpResponseHeader(0x12, str);
                    }
                    if (this._isLastModifiedSet)
                    {
                        string str2 = HttpUtility.FormatHttpDateTimeUtc(this._utcLastModified);
                        this._headerLastModified = new HttpResponseHeader(0x13, str2);
                    }
                    if (@private != HttpCacheability.Private)
                    {
                        bool omitVaryStar;
                        if (this._etag != null)
                        {
                            this._headerEtag = new HttpResponseHeader(0x16, this._etag);
                        }
                        string str3 = null;
                        if (this._omitVaryStar != -1)
                        {
                            omitVaryStar = this._omitVaryStar == 1;
                        }
                        else
                        {
                            OutputCacheSection outputCache = RuntimeConfig.GetLKGConfig(response.Context).OutputCache;
                            if (outputCache != null)
                            {
                                omitVaryStar = outputCache.OmitVaryStar;
                            }
                            else
                            {
                                omitVaryStar = false;
                            }
                        }
                        if (!omitVaryStar && ((this._varyByCustom != null) || (this._varyByParams.IsModified() && !this._varyByParams.IgnoreParams)))
                        {
                            str3 = "*";
                        }
                        if (str3 == null)
                        {
                            str3 = this._varyByHeaders.ToHeaderString();
                        }
                        if (str3 != null)
                        {
                            this._headerVaryBy = new HttpResponseHeader(0x1c, str3);
                        }
                    }
                    break;
                }
                this._useCachedHeaders = true;
            }
        }
Exemple #13
0
        internal void ResetFromHttpCachePolicySettings(HttpCachePolicySettings settings, DateTime utcTimestampRequest)
        {
            int num;
            int length;

            this._utcTimestampRequest = utcTimestampRequest;
            this._varyByContentEncodings.ResetFromContentEncodings(settings.VaryByContentEncodings);
            this._varyByHeaders.ResetFromHeaders(settings.VaryByHeaders);
            this._varyByParams.ResetFromParams(settings.VaryByParams);
            this._isModified          = settings.IsModified;
            this._hasSetCookieHeader  = settings.hasSetCookieHeader;
            this._noServerCaching     = settings.NoServerCaching;
            this._cacheExtension      = settings.CacheExtension;
            this._noTransforms        = settings.NoTransforms;
            this._ignoreRangeRequests = settings.IgnoreRangeRequests;
            this._varyByCustom        = settings.VaryByCustom;
            this._cacheability        = settings.CacheabilityInternal;
            this._noStore             = settings.NoStore;
            this._utcExpires          = settings.UtcExpires;
            this._isExpiresSet        = settings.IsExpiresSet;
            this._maxAge              = settings.MaxAge;
            this._isMaxAgeSet         = settings.IsMaxAgeSet;
            this._proxyMaxAge         = settings.ProxyMaxAge;
            this._isProxyMaxAgeSet    = settings.IsProxyMaxAgeSet;
            this._slidingExpiration   = settings.SlidingExpirationInternal;
            this._slidingDelta        = settings.SlidingDelta;
            this._utcTimestampCreated = settings.UtcTimestampCreated;
            this._validUntilExpires   = settings.ValidUntilExpiresInternal;
            this._allowInHistory      = settings.AllowInHistoryInternal;
            this._revalidation        = settings.Revalidation;
            this._utcLastModified     = settings.UtcLastModified;
            this._isLastModifiedSet   = settings.IsLastModifiedSet;
            this._etag = settings.ETag;
            this._generateLastModifiedFromFiles = settings.GenerateLastModifiedFromFiles;
            this._generateEtagFromFiles         = settings.GenerateEtagFromFiles;
            this._omitVaryStar = settings.OmitVaryStarInternal;
            this._hasUserProvidedDependencies = settings.HasUserProvidedDependencies;
            this._useCachedHeaders            = true;
            this._headerCacheControl          = settings.HeaderCacheControl;
            this._headerPragma           = settings.HeaderPragma;
            this._headerExpires          = settings.HeaderExpires;
            this._headerLastModified     = settings.HeaderLastModified;
            this._headerEtag             = settings.HeaderEtag;
            this._headerVaryBy           = settings.HeaderVaryBy;
            this._noMaxAgeInCacheControl = false;
            string[] privateFields = settings.PrivateFields;
            if (privateFields != null)
            {
                this._privateFields = new HttpDictionary();
                num    = 0;
                length = privateFields.Length;
                while (num < length)
                {
                    this._privateFields.SetValue(privateFields[num], privateFields[num]);
                    num++;
                }
            }
            privateFields = settings.NoCacheFields;
            if (privateFields != null)
            {
                this._noCacheFields = new HttpDictionary();
                num    = 0;
                length = privateFields.Length;
                while (num < length)
                {
                    this._noCacheFields.SetValue(privateFields[num], privateFields[num]);
                    num++;
                }
            }
            if (settings.ValidationCallbackInfo != null)
            {
                this._validationCallbackInfo = new ArrayList();
                num    = 0;
                length = settings.ValidationCallbackInfo.Length;
                while (num < length)
                {
                    this._validationCallbackInfo.Add(new ValidationCallbackInfo(settings.ValidationCallbackInfo[num].handler, settings.ValidationCallbackInfo[num].data));
                    num++;
                }
            }
        }
Exemple #14
0
        internal void GetHeaders(ArrayList headers, HttpResponse response)
        {
            this.UpdateCachedHeaders(response);
            HttpResponseHeader header  = this._headerExpires;
            HttpResponseHeader header2 = this._headerCacheControl;

            if ((this._cacheability != HttpCacheability.NoCache) && (this._cacheability != HttpCacheability.Server))
            {
                if (this._slidingExpiration == 1)
                {
                    if (this._isExpiresSet)
                    {
                        DateTime dt  = this._utcTimestampRequest + this._slidingDelta;
                        string   str = HttpUtility.FormatHttpDateTimeUtc(dt);
                        header = new HttpResponseHeader(0x12, str);
                    }
                }
                else if (this._isMaxAgeSet || this._isProxyMaxAgeSet)
                {
                    StringBuilder builder;
                    if (header2 != null)
                    {
                        builder = new StringBuilder(header2.Value);
                    }
                    else
                    {
                        builder = new StringBuilder();
                    }
                    TimeSpan span = (TimeSpan)(this._utcTimestampRequest - this._utcTimestampCreated);
                    if (this._isMaxAgeSet)
                    {
                        TimeSpan zero = this._maxAge - span;
                        if (zero < TimeSpan.Zero)
                        {
                            zero = TimeSpan.Zero;
                        }
                        if (!this._noMaxAgeInCacheControl)
                        {
                            AppendValueToHeader(builder, "max-age=" + ((long)zero.TotalSeconds).ToString(CultureInfo.InvariantCulture));
                        }
                    }
                    if (this._isProxyMaxAgeSet)
                    {
                        TimeSpan span3 = this._proxyMaxAge - span;
                        if (span3 < TimeSpan.Zero)
                        {
                            span3 = TimeSpan.Zero;
                        }
                        if (!this._noMaxAgeInCacheControl)
                        {
                            AppendValueToHeader(builder, "s-maxage=" + ((long)span3.TotalSeconds).ToString(CultureInfo.InvariantCulture));
                        }
                    }
                    header2 = new HttpResponseHeader(0, builder.ToString());
                }
            }
            if (header2 != null)
            {
                headers.Add(header2);
            }
            if (this._headerPragma != null)
            {
                headers.Add(this._headerPragma);
            }
            if (header != null)
            {
                headers.Add(header);
            }
            if (this._headerLastModified != null)
            {
                headers.Add(this._headerLastModified);
            }
            if (this._headerEtag != null)
            {
                headers.Add(this._headerEtag);
            }
            if (this._headerVaryBy != null)
            {
                headers.Add(this._headerVaryBy);
            }
        }
Exemple #15
0
 public string this[HttpResponseHeader index]
 {
     get { return _responseHeaders[index]; }
 }
 /// <summary>
 /// Append header to response
 /// </summary>
 /// <remarks>
 /// Seems like appendheader only works with IIS 7
 /// </remarks>
 /// <param name="response"></param>
 /// <param name="httpResponseHeader"></param>
 /// <param name="headerValue"></param>
 public void AppendHeader(HttpResponseBase response, HttpResponseHeader httpResponseHeader, string headerValue)
 {
     var httpResponseHeaderString = (string)httpResponseHeader;
     AppendHeader(response, httpResponseHeaderString, headerValue);
 }
 public IEnumerable<string> HeaderValueFor(HttpResponseHeader key)
 {
     return HeaderValueFor(HttpResponseHeaders.HeaderNameFor(key));
 }
        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;
        }
		private ArrayList GenerateHeaders ()
		{
			ArrayList oHeaders = new ArrayList (_Headers);

			oHeaders.Add (new HttpResponseHeader ("X-Powered-By", "Mono"));

#if !TARGET_J2EE
			string date = DateTime.UtcNow.ToString ("ddd, d MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture);
			HttpResponseHeader date_header = new HttpResponseHeader ("Date", date);
			oHeaders.Add (date_header);
			
			if (IsCached)
				cached_response.DateHeader = date_header;

			if (_lContentLength > 0) {
				oHeaders.Add (new HttpResponseHeader (HttpWorkerRequest.HeaderContentLength,
								      _lContentLength.ToString ()));
			}
#endif

			// Apache2 only auto-adds 'charset=blah' for text/plain and text/html
			if (_sContentType != null) {
				string ctype = _sContentType;
				if (forced_charset || _sContentType == "text/plain" || _sContentType == "text/html") {
					if (_sContentType.IndexOf ("charset=") == -1) {
						if (Charset.Length == 0)
							Charset = ContentEncoding.HeaderName;

						// Time to build our string
						if (Charset.Length > 0)
							ctype += "; charset=" + Charset;
					}
				}

				oHeaders.Add (new HttpResponseHeader (HttpWorkerRequest.HeaderContentType, ctype));
			}

			if (_CachePolicy != null)
				_CachePolicy.SetHeaders (this, oHeaders);
			
			if (_sCacheControl != null) {
				oHeaders.Add (new HttpResponseHeader (HttpWorkerRequest.HeaderPragma,
								      _sCacheControl));
			}

			if (_sTransferEncoding != null) {
				oHeaders.Add (new HttpResponseHeader (HttpWorkerRequest.HeaderTransferEncoding,
								      _sTransferEncoding));
			}

			if (_Cookies != null) {
				int length = _Cookies.Count;
				for (int i = 0; i < length; i++) {
					oHeaders.Add (_Cookies.Get (i).GetCookieHeader ());
				}
			}
#if NET_1_1
			if (redirectLocation != null)
				oHeaders.Add (new HttpResponseHeader (HttpWorkerRequest.HeaderLocation,
								      redirectLocation));
#endif
			return oHeaders;
		}
        /*
         * Reset based on a cached response. Includes data needed to generate
         * header for a cached response.
         */
        internal void ResetFromHttpCachePolicySettings(
                HttpCachePolicySettings settings,
                DateTime                utcTimestampRequest) {

            int i, n;
            string[] fields;
            
            _utcTimestampRequest = utcTimestampRequest;

            _varyByContentEncodings.ResetFromContentEncodings(settings.VaryByContentEncodings);
            _varyByHeaders.ResetFromHeaders(settings.VaryByHeaders);                          
            _varyByParams.ResetFromParams(settings.VaryByParams);

            _isModified                       = settings.IsModified;                    
            _hasSetCookieHeader               = settings.hasSetCookieHeader;
            _noServerCaching                  = settings.NoServerCaching;               
            _cacheExtension                   = settings.CacheExtension;                
            _noTransforms                     = settings.NoTransforms;                  
            _ignoreRangeRequests              = settings.IgnoreRangeRequests;
            _varyByCustom                     = settings.VaryByCustom;
            _cacheability                     = settings.CacheabilityInternal;                  
            _noStore                          = settings.NoStore;
            _utcExpires                       = settings.UtcExpires;                       
            _isExpiresSet                     = settings.IsExpiresSet;                  
            _maxAge                           = settings.MaxAge;                        
            _isMaxAgeSet                      = settings.IsMaxAgeSet;                   
            _proxyMaxAge                      = settings.ProxyMaxAge;                   
            _isProxyMaxAgeSet                 = settings.IsProxyMaxAgeSet;              
            _slidingExpiration                = settings.SlidingExpirationInternal;             
            _slidingDelta                     = settings.SlidingDelta;
            _utcTimestampCreated              = settings.UtcTimestampCreated;
            _validUntilExpires                = settings.ValidUntilExpiresInternal;
            _allowInHistory                   = settings.AllowInHistoryInternal;
            _revalidation                     = settings.Revalidation;                  
            _utcLastModified                  = settings.UtcLastModified;                  
            _isLastModifiedSet                = settings.IsLastModifiedSet;             
            _etag                             = settings.ETag;                          
            _generateLastModifiedFromFiles    = settings.GenerateLastModifiedFromFiles; 
            _generateEtagFromFiles            = settings.GenerateEtagFromFiles;         
            _omitVaryStar                     = settings.OmitVaryStarInternal;
            _hasUserProvidedDependencies      = settings.HasUserProvidedDependencies;

            _useCachedHeaders = true;
            _headerCacheControl = settings.HeaderCacheControl;
            _headerPragma = settings.HeaderPragma;        
            _headerExpires = settings.HeaderExpires;       
            _headerLastModified = settings.HeaderLastModified;  
            _headerEtag = settings.HeaderEtag;          
            _headerVaryBy = settings.HeaderVaryBy;        

            _noMaxAgeInCacheControl = false;

            fields = settings.PrivateFields;
            if (fields != null) {
                _privateFields = new HttpDictionary();
                for (i = 0, n = fields.Length; i < n; i++) {
                    _privateFields.SetValue(fields[i], fields[i]);
                }
            }

            fields = settings.NoCacheFields;
            if (fields != null) {
                _noCacheFields = new HttpDictionary();
                for (i = 0, n = fields.Length; i < n; i++) {
                    _noCacheFields.SetValue(fields[i], fields[i]);
                }
            }

            if (settings.ValidationCallbackInfo != null) {
                _validationCallbackInfo = new ArrayList();
                for (i = 0, n = settings.ValidationCallbackInfo.Length; i < n; i++) {
                    _validationCallbackInfo.Add(new ValidationCallbackInfo(
                            settings.ValidationCallbackInfo[i].handler,
                            settings.ValidationCallbackInfo[i].data));
                }
            }
        }
 private void AppendHeader(HttpResponseHeader h)
 {
     if (this._customHeaders == null)
     {
         this._customHeaders = new ArrayList();
     }
     this._customHeaders.Add(h);
     if ((this._cachePolicy != null) && System.Web.Util.StringUtil.EqualsIgnoreCase("Set-Cookie", h.Name))
     {
         this._cachePolicy.SetHasSetCookieHeader();
     }
 }
        /*
         * Generate headers and append them to the list
         */
        internal void GetHeaders(ArrayList headers, HttpResponse response) {
            StringBuilder       sb;
            String              expirationDate;           
            TimeSpan            age, maxAge, proxyMaxAge; 
            DateTime            utcExpires;                  
            HttpResponseHeader  headerExpires;
            HttpResponseHeader  headerCacheControl;

            UpdateCachedHeaders(response);
            headerExpires = _headerExpires;
            headerCacheControl = _headerCacheControl;

            /* 
             * reconstruct headers that vary with time 
             * don't send expiration information when item shouldn't be cached
             */
            if (_cacheability != HttpCacheability.NoCache && _cacheability != HttpCacheability.ServerAndNoCache) {
                if (_slidingExpiration == 1) {
                    /* update Expires header */
                    if (_isExpiresSet) {
                        utcExpires = _utcTimestampRequest + _slidingDelta;
                        expirationDate = HttpUtility.FormatHttpDateTimeUtc(utcExpires);
                        headerExpires = new HttpResponseHeader(HttpWorkerRequest.HeaderExpires, expirationDate);
                    }
                }
                else {
                    if (_isMaxAgeSet || _isProxyMaxAgeSet) {
                        /* update max-age, s-maxage components of Cache-Control header */
                        if (headerCacheControl != null) {
                            sb = new StringBuilder(headerCacheControl.Value);
                        }
                        else {
                            sb = new StringBuilder();
                        }

                        age = _utcTimestampRequest - _utcTimestampCreated;
                        if (_isMaxAgeSet) {
                            maxAge = _maxAge - age;
                            if (maxAge < TimeSpan.Zero) {
                                maxAge = TimeSpan.Zero;
                            }

                            if (!_noMaxAgeInCacheControl)
                                AppendValueToHeader(sb, "max-age=" + ((long)maxAge.TotalSeconds).ToString(CultureInfo.InvariantCulture));
                        }

                        if (_isProxyMaxAgeSet) {
                            proxyMaxAge = _proxyMaxAge - age;
                            if (proxyMaxAge < TimeSpan.Zero) {
                                proxyMaxAge = TimeSpan.Zero;
                            }

                            if (!_noMaxAgeInCacheControl)
                                AppendValueToHeader(sb, "s-maxage=" + ((long)(proxyMaxAge).TotalSeconds).ToString(CultureInfo.InvariantCulture));
                        }

                        headerCacheControl = new HttpResponseHeader(HttpWorkerRequest.HeaderCacheControl, sb.ToString());
                    }
                }
            }

            if (headerCacheControl != null) {
                headers.Add(headerCacheControl);
            }

            if (_headerPragma != null) {
                headers.Add(_headerPragma);
            }

            if (headerExpires != null) {
                headers.Add(headerExpires);
            }

            if (_headerLastModified != null) {
                headers.Add(_headerLastModified);
            }

            if (_headerEtag != null) {
                headers.Add(_headerEtag);
            }

            if (_headerVaryBy != null) {
                headers.Add(_headerVaryBy);
            }
        }
        public void AppendHeader(string name, string value)
        {
            bool flag = false;
            if (this._headersWritten)
            {
                throw new HttpException(System.Web.SR.GetString("Cannot_append_header_after_headers_sent"));
            }
            int knownResponseHeaderIndex = HttpWorkerRequest.GetKnownResponseHeaderIndex(name);
            switch (knownResponseHeaderIndex)
            {
                case 0:
                    this._cacheControlHeaderAdded = true;
                    break;

                case 6:
                    this._transferEncodingSet = true;
                    goto Label_0095;

                case 11:
                    this._contentLengthSet = true;
                    goto Label_0095;

                case 12:
                    this.ContentType = value;
                    return;

                case 0x12:
                case 0x13:
                case 0x16:
                case 0x1c:
                    break;

                case 0x17:
                    this.RedirectLocation = value;
                    return;

                default:
                    goto Label_0095;
            }
            flag = true;
        Label_0095:
            if (this._wr is IIS7WorkerRequest)
            {
                this.Headers.Add(name, value);
            }
            else if (flag)
            {
                if (this._cacheHeaders == null)
                {
                    this._cacheHeaders = new ArrayList();
                }
                this._cacheHeaders.Add(new HttpResponseHeader(knownResponseHeaderIndex, value));
            }
            else
            {
                HttpResponseHeader header;
                if (knownResponseHeaderIndex >= 0)
                {
                    header = new HttpResponseHeader(knownResponseHeaderIndex, value);
                }
                else
                {
                    header = new HttpResponseHeader(name, value);
                }
                this.AppendHeader(header);
            }
        }