System.Web.HttpResponse.AddHeadersNoCache C# (CSharp) Method

AddHeadersNoCache() private method

private AddHeadersNoCache ( NameValueCollection write_headers, bool final_flush ) : void
write_headers System.Collections.Specialized.NameValueCollection
final_flush bool
return void
		void AddHeadersNoCache (NameValueCollection write_headers, bool final_flush)
		{
#if !TARGET_J2EE
			//
			// Transfer-Encoding
			//
			if (use_chunked)
				write_headers.Add ("Transfer-Encoding", "chunked");
			else if (transfer_encoding != null)
				write_headers.Add ("Transfer-Encoding", transfer_encoding);
#endif
			if (redirect_location != null)
				write_headers.Add ("Location", redirect_location);
			
#if !TARGET_J2EE
			string vh = VersionHeader;
			if (vh != null)
				write_headers.Add ("X-AspNet-Version", vh);

			//
			// If Content-Length is set.
			//
			if (content_length >= 0) {
				write_headers.Add (HttpWorkerRequest.GetKnownResponseHeaderName (HttpWorkerRequest.HeaderContentLength),
						   content_length.ToString (Helpers.InvariantCulture));
			} else if (BufferOutput) {
				if (final_flush) {					
					//
					// If we are buffering and this is the last flush, not a middle-flush,
					// we know the content-length.
					//
					content_length = output_stream.total;
					write_headers.Add (HttpWorkerRequest.GetKnownResponseHeaderName (HttpWorkerRequest.HeaderContentLength),
							   content_length.ToString (Helpers.InvariantCulture));
				} else {
					//
					// We are buffering, and this is a flush in the middle.
					// If we are not chunked, we need to set "Connection: close".
					//
					if (use_chunked){
						write_headers.Add (HttpWorkerRequest.GetKnownResponseHeaderName (HttpWorkerRequest.HeaderConnection), "close");
					}
				}
			} else {
				//
				// If the content-length is not set, and we are not buffering, we must
				// close at the end.
				//
				if (use_chunked){
					write_headers.Add (HttpWorkerRequest.GetKnownResponseHeaderName (HttpWorkerRequest.HeaderConnection), "close");
				}
			}
#endif

			//
			// Cache Control, the cache policy takes precedence over the cache_control property.
			//
			if (cache_policy != null)
				cache_policy.SetHeaders (this, headers);
			else
				write_headers.Add ("Cache-Control", CacheControl);
			
			//
			// Content-Type
			//
			if (content_type != null){
				string header = content_type;

				if (charset_set || header == "text/plain" || header == "text/html") {
					if (header.IndexOf ("charset=") == -1) {
						if (charset == null || charset == "")
							charset = ContentEncoding.HeaderName;
						header += "; charset=" + charset;
					}
				}
				
				write_headers.Add ("Content-Type", header);
			}

			if (cookies != null && cookies.Count != 0){
				int n = cookies.Count;
				for (int i = 0; i < n; i++)
					write_headers.Add ("Set-Cookie", cookies.Get (i).GetCookieHeaderValue ());
#if TARGET_J2EE
				// For J2EE Portal support emulate cookies by storing them in the session.
				context.Request.SetSessionCookiesForPortal (cookies);
#endif
			}
		}