Commits

gustafn committed 8605b95

- extend ns_setexpires such one can include chache-reponse-directives (see section 14.9 of rfc2616)

Comments (0)

Files changed (2)

doc/src/naviserver/ns_setexpires.man

 [manpage_begin ns_setexpires n [vset version]]
 [moddesc {NaviServer Built-in Commands}]
 
-[titledesc {Set the current connections Expires header to the current time plus seconds seconds}]
+[titledesc {Set the current connections Expires header field to the current time plus seconds seconds}]
 
 [description]
 
 [section {COMMANDS}]
 
 [list_begin definitions]
-
-
-[call [cmd ns_setexpires] [arg seconds]]
-
-
+[call [cmd ns_setexpires] \
+	[opt [option "--cache-control [arg cache-response-directive]"]] \
+	[arg seconds]]
 [list_end]
 
+Set the output headers contain the "Expires" header. When
+"-cache-control" is specified the function adds as well a "max-age"
+header field to the response with the specified cache response
+directive (such as public, private, no-cache, no-store, no-transform,
+must-revalidate, or proxy-revalidate)
 
 [section EXAMPLES]
 
    % ns_setexpires 60
 [example_end]
 
-Set the Expires header to expire in 1 minute from now
+Set the "Expires" header field to expire in 1 minute from now.
 
 
-[see_also nsd]
-[keywords ns_time ns_conn]
+[keywords cache]
+[see_also ns_time ns_conn]
 
 [manpage_end]
 
 #
 # ns_setexpires --
 #
-#   Assures connection output headers contain the
-#   Expires header.
+#   Assures connection output headers contain the "Expires"
+#   header. When "-cache-control" is specified the function adds as
+#   well a max-age header field to the response with the specified
+#   cache response directive (such as public, private, no-cache,
+#   no-store, no-transform, must-revalidate, or proxy-revalidate)
 #
 # Results:
 #   None.
 #   Output headers set may be extended.
 #
 
-proc ns_setexpires {secs} {
+proc ns_setexpires {args} {
+    set headers [ns_conn outputheaders]
+    set secs [lindex $args end]
+    if {[lindex $args 0] eq "-cache-control"} {
+        set cache_control [lindex $args 1]
+        ns_set update $headers Cache-Control "max-age=$secs, [lindex $args 1]"
+    } elseif {[llength $args] > 1} {
+	error "usage: ns_setexpires ?-cache-control public|private|no-cache|no-store|no-transform|must-revalidate|proxy-revalidate? secs"
+    }
     set when [ns_httptime [expr {$secs + [clock seconds]}]]
-    ns_set update [ns_conn outputheaders] Expires $when
+    ns_set update $headers Expires $when
 }