Hi all,
I found that there is no option to override the Expires header with
mod_expires. Especially when you use apache (with mod_cache) as a
reverse proxy it can be very useful to be able to override the expires
headers. I've created a patch for mod_expires for the 2.2.x branch
(trunk is similar) which adds the option "ExpiresOverride On|Off".
Are there more people interested to have this in the 2.2.x branch or trunk?
Regards,
Bart
--- httpd-2.2.x-orig/modules/metadata/mod_expires.c 2006-07-13
16:18:03.000000000 +0200
+++ httpd-2.2.x/modules/metadata/mod_expires.c 2006-07-13 16:19:21.000000000
+0200
@@ -167,6 +167,7 @@
typedef struct {
int active;
+ int override;
int wildcards;
char *expiresdefault;
apr_table_t *expiresbytype;
@@ -176,6 +177,9 @@
*/
#define DIR_CMD_PERMS OR_INDEXES
+#define OVERRIDE_ON 1
+#define OVERRIDE_OFF 0
+#define OVERRIDE_DONTCARE 2
#define ACTIVE_ON 1
#define ACTIVE_OFF 0
#define ACTIVE_DONTCARE 2
@@ -187,12 +191,28 @@
expires_dir_config *new =
(expires_dir_config *) apr_pcalloc(p, sizeof(expires_dir_config));
new->active = ACTIVE_DONTCARE;
+ new->override = OVERRIDE_DONTCARE;
new->wildcards = 0;
new->expiresdefault = NULL;
new->expiresbytype = apr_table_make(p, 4);
return (void *) new;
}
+static const char *set_expiresoverride(cmd_parms *cmd, void *in_dir_config,
int arg)
+{
+ expires_dir_config *dir_config = in_dir_config;
+
+ /* if we're here at all it's because someone explicitly
+ * set the override flag
+ */
+
+ dir_config->override = OVERRIDE_ON;
+ if (arg == 0) {
+ dir_config->override = OVERRIDE_OFF;
+ }
+ return NULL;
+}
+
static const char *set_expiresactive(cmd_parms *cmd, void *in_dir_config, int
arg)
{
expires_dir_config *dir_config = in_dir_config;
@@ -351,6 +371,8 @@
{
AP_INIT_FLAG("ExpiresActive", set_expiresactive, NULL, DIR_CMD_PERMS,
"Limited to 'on' or 'off'"),
+ AP_INIT_FLAG("ExpiresOverride", set_expiresoverride, NULL, DIR_CMD_PERMS,
+ "Limited to 'on' or 'off'"),
AP_INIT_TAKE2("ExpiresByType", set_expiresbytype, NULL, DIR_CMD_PERMS,
"a MIME type followed by an expiry date code"),
AP_INIT_TAKE1("ExpiresDefault", set_expiresdefault, NULL, DIR_CMD_PERMS,
@@ -371,6 +393,13 @@
new->active = add->active;
}
+ if (add->override == OVERRIDE_DONTCARE ) {
+ new->override = base->active;
+ }
+ else {
+ new->override = add->override;
+ }
+
if (add->expiresdefault != NULL) {
new->expiresdefault = add->expiresdefault;
}
@@ -427,7 +456,7 @@
}
expires = base + additional;
- apr_table_mergen(t, "Cache-Control",
+ apr_table_setn(t, "Cache-Control",
apr_psprintf(r->pool, "max-age=%" APR_TIME_T_FMT,
apr_time_sec(expires - r->request_time)));
timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
@@ -466,7 +495,7 @@
expiry = apr_table_get(r->headers_out, "Expires");
t = r->headers_out;
}
- if (expiry == NULL) {
+ if (expiry == NULL || (conf->override == OVERRIDE_ON)) {
/*
* No expiration has been set, so we can apply any managed by
* this module. First, check to see if there is an applicable