+ + It should be called only when the method to return the data to the + client is going to be ns_return. In other cases, e.g. ns_returnfile, + one can assume that the returned content is not dynamic and can in + fact be cached. Besides that, aolserver implements its own handling + of Last-Modified headers with ns_returnfile. Also it should be + called as late as possible - shortly before ns_return, so that + other code has the chance to set no_cache_control_p to 1 before + it runs. + +
+ + This proc can be disabled per request by calling + "ad_conn -set no_http_cache_control_p 1" before this proc is reached. + It will not modify any headers if this variable is set to 1. + +
+ + If the acs-kernel parameter CacheControlP is set to 0 then + it's fully disabled. + + @author Tilmann Singer (tils-oacs@tils.net) + +} { + + if { ![parameter::get -package_id [ad_acs_kernel_id] -parameter HttpCacheControlP -default 0]} { + return + } + + global ad_conn + if { [info exists ad_conn(no_http_cache_control_p)] && $ad_conn(no_http_cache_control_p) } { + return + } + + set headers [ad_conn outputheaders] + + # Check if any relevant header is already present - in this case + # don't touch anything. + set modify_p 1 + + if { ([ns_set ifind $headers "cache-control"] > -1 || + [ns_set ifind $headers "expires"] > -1) } { + set modify_p 0 + } else { + for { set i 0 } { $i < [ns_set size $headers] } { incr i } { + if { [string tolower [ns_set key $headers $i]] == "pragma" && + [string tolower [ns_set value $headers $i]] == "no-cache" } { + set modify_p 0 + break + } + } + } + + # Set three headers, to be sure it won't get cached. If you are in + # doubt, check the spec: + # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html + + if { $modify_p } { + # actually add the headers + ns_setexpires 0 + ns_set put $headers "Pragma" "no-cache" + ns_set put $headers "Cache-Control" "no-cache" + } + + # Prevent subsequent calls of this proc from adding the same + # headers again. + ad_conn -set no_http_cache_control_p 1 +} + + # ------------------------------------------------------------------------- # procs for hostname-based subsites # ------------------------------------------------------------------------- @@ -1262,3 +1339,4 @@ ad_proc -private rp_lookup_node_from_host { host } { return [db_string node_id { *SQL* } -default ""] } + Index: openacs-4/packages/acs-templating/tcl/acs-integration-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/acs-integration-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-templating/tcl/acs-integration-procs.tcl 31 Aug 2002 02:01:41 -0000 1.5 +++ openacs-4/packages/acs-templating/tcl/acs-integration-procs.tcl 12 Feb 2003 18:43:51 -0000 1.6 @@ -85,12 +85,12 @@ ad_conn -set subsite_id [site_node_closest_ancestor_package "acs-subsite"] set parsed_template [template::adp_parse [file root [ad_conn file]] {}] - db_release_unused_handles if {![empty_string_p $parsed_template]} { set mime_type [template::get_mime_type] set header_preamble [template::get_mime_header_preamble $mime_type] - - ns_return 200 $mime_type "$header_preamble $parsed_template" + doc_return 200 $mime_type "$header_preamble $parsed_template" + } else { + db_release_unused_handles } }