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; } }
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); } }