Skip to content

Instantly share code, notes, and snippets.

@justis
Created September 7, 2011 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justis/1201513 to your computer and use it in GitHub Desktop.
Save justis/1201513 to your computer and use it in GitHub Desktop.
no client caching for www/resources on development systems
ad_proc -private rp_resources_filter { why } {
This filter runs on all URLs of the form /resources/*. The acs-resources package
mounts itself at /resources but we short circuit references here in order to
maximize throughput for resource files. We just ns_returnfile the file, no
permissions are checked, the ad_conn structure is not initialized, etc.
There are two mapping possibilities:
/resources/package-key/* maps to root/packages/package-key/www/resources/*
If that fails, we map to root/www/resources/*
If the file doesn't exist we'll log an error and return filter_ok, which will allow
packages mounted at "/resources" in a legacy site to work correctly. This is a
horrible kludge which may disappear after discussion with the gang.
@author Don Baccus (dhogaza@pacifier.com)
} {
set path "[acs_package_root_dir [lindex [ns_conn urlv] 1]]/www/resources/[join [lrange [ns_conn urlv] 2 end] /]"
if { ![file isfile $path] } {
set path "[acs_root_dir]/www/resources/[join [lrange [ns_conn urlv] 1 end] /]"
}
if { [file isfile $path] } {
# TODO make this vary between dev and prod
set headers [ns_conn outputheaders]
if { 1 } {
ns_setexpires 0
ns_set put $headers "Pragma" "no-cache"
ns_set put $headers "Cache-Control" "no-cache"
}
ns_returnfile 200 [ns_guesstype $path] $path
return filter_return
} else {
ns_log Error "rp_sources_filter: file \"$path\" does not exists trying to serve as a normal request"
return filter_ok
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment