You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rob Hartill <ro...@imdb.com> on 1997/06/26 23:55:01 UTC

[PATCH] mod_expires.c

An user provided a patch during the 1.2 beta phase to extend mod_expires.c.
I didn't need/want all the extra stuff so just added my own simple
"Cache-Control:" option.

Here's the patch. It also make mod_expires more efficient by jumping out
earlier when it's wasting time and effort on no-hope cases. The call to
"get_module_config" is made only when needed now.


Index: mod_expires.c
===================================================================
RCS file: /imdb/cvs/apache/src/mod_expires.c,v
retrieving revision 1.5
diff -u -r1.5 mod_expires.c
--- mod_expires.c	1997/06/19 23:54:01	1.5
+++ mod_expires.c	1997/06/26 21:51:39
@@ -384,18 +384,23 @@
 
 int add_expires(request_rec *r)
 {
-    expires_dir_config *conf =
-            (expires_dir_config *)get_module_config(r->per_dir_config, &expires_module);
+    expires_dir_config *conf;
     char *code;
     time_t base; 
     time_t additional; 
     time_t expires; 
+    char age[20];
 
-    if ( r->finfo.st_mode == 0 )
+    if (is_HTTP_ERROR(r->status))  /* Don't add Expires headers to errors */
 	return DECLINED;
 
-    /* COMMA bites my ass...
-     */
+    if (r->main != NULL)           /* Say no to subrequests */
+	return DECLINED;
+
+    if ( r->finfo.st_mode == 0 )     /* no file ? shame. */
+	return DECLINED;
+
+    conf = (expires_dir_config *)get_module_config(r->per_dir_config, &expires_module);
     if ( conf == NULL ) {
         log_reason ("internal error in expires_module; add_expires(), conf == NULL", r->filename, r);
 	return SERVER_ERROR;
@@ -451,6 +456,8 @@
     };
 
     expires = base + additional;
+    ap_snprintf(age, sizeof(age), "max-age=%d", (int)expires - (int)time(NULL));
+    table_set( r->headers_out, "Cache-Control", age);
     tzset();	/* redundant? called implicitly by localtime, at least 
 		 * under FreeBSD
 		 */