/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/
/* * mod_expires.c * version 0.0.11 * status beta * * Andrew Wilson <Andrew.Wilson@cm.cf.ac.uk> 26.Jan.96 * * This module allows you to control the form of the Expires: header * that Apache issues for each access. Directives can appear in * configuration files or in .htaccess files so expiry semantics can * be defined on a per-directory basis. * * DIRECTIVE SYNTAX * * Valid directives are: * * ExpiresActive on | off * ExpiresDefault <code><seconds> * ExpiresByType type/encoding <code><seconds> * * Valid values for <code> are: * * 'M' expires header shows file modification date + <seconds> * 'A' expires header shows access time + <seconds> * * [I'm not sure which of these is best under different * circumstances, I guess it's for other people to explore. * The effects may be indistinguishable for a number of cases] * * <seconds> should be an integer value [acceptable to atoi()] * * There is NO space between the <code> and <seconds>. * * For example, a directory which contains information which changes * frequently might contain: * * # reports generated by cron every hour. don't let caches * # hold onto stale information * ExpiresDefault M3600 * * Another example, our html pages can change all the time, the gifs * tend not to change often: * * # pages are hot (1 week), images are cold (1 month) * ExpiresByType text/html A604800 * ExpiresByType image/gif A2592000 * * Expires can be turned on for all URLs on the server by placing the * following directive in a conf file: * * ExpiresActive on * * ExpiresActive can also appear in .htaccess files, enabling the * behaviour to be turned on or off for each chosen directory. * * # turn off Expires behaviour in this directory * # and subdirectories * ExpiresActive off * * Directives defined for a directory are valid in subdirectories * unless explicitly overridden by new directives in the subdirectory * .htaccess files. * * ALTERNATIVE DIRECTIVE SYNTAX * * Directives can also be defined in a more readable syntax of the form: * * ExpiresDefault "<base> [plus] {<num> <type>}*" * ExpiresByType type/encoding "<base> [plus] {<num> <type>}*" * * where <base> is one of: * access * now equivalent to 'access' * modification * * where the 'plus' keyword is optional * * where <num> should be an integer value [acceptable to atoi()] * * where <type> is one of: * years * months * weeks * days * hours * minutes * seconds * * For example, any of the following directives can be used to make * documents expire 1 month after being accessed, by default: * * ExpiresDefault "access plus 1 month" * ExpiresDefault "access plus 4 weeks" * ExpiresDefault "access plus 30 days" * * The expiry time can be fine-tuned by adding several '<num> <type>' * clauses: * * ExpiresByType text/html "access plus 1 month 15 days 2 hours" * ExpiresByType image/gif "modification plus 5 hours 3 minutes" * * --- * * Change-log: * 29.Jan.96 Hardened the add_* functions. Server will now bail out * if bad directives are given in the conf files. * 02.Feb.96 Returns DECLINED if not 'ExpiresActive on', giving other * expires-aware modules a chance to play with the same * directives. [Michael Rutman] * 03.Feb.96 Call tzset() before localtime(). Trying to get the module * to work properly in non GMT timezones. * 12.Feb.96 Modified directive syntax to allow more readable commands: * ExpiresDefault "now plus 10 days 20 seconds" * ExpiresDefault "access plus 30 days" * ExpiresDefault "modification plus 1 year 10 months 30 days" * 13.Feb.96 Fix call to table_get() with NULL 2nd parameter [Rob Hartill] * 19.Feb.96 Call gm_timestr_822() to get time formatted correctly, can't * rely on presence of HTTP_TIME_FORMAT in Apache 1.1+. * 21.Feb.96 This version (0.0.9) reverses assumptions made in 0.0.8 * about star/star handlers. Reverting to 0.0.7 behaviour. * 08.Jun.96 allows ExpiresDefault to be used with responses that use * the DefaultType by not DECLINING, but instead skipping * the table_get check and then looking for an ExpiresDefault. * [Rob Hartill] * 04.Nov.96 'const' definitions added. * * TODO * add support for Cache-Control: max-age=20 from the HTTP/1.1 * proposal (in this case, a ttl of 20 seconds) [ask roy] * add per-file expiry and explicit expiry times - duplicates some * of the mod_cern_meta.c functionality. eg: * ExpiresExplicit index.html "modification plus 30 days" * * BUGS * Hi, welcome to the internet.
*/
/* if we're here at all it's because someone explicitly * set the active flag
*/
dir_config->active = ACTIVE_ON; if (arg == 0) {
dir_config->active = ACTIVE_OFF;
} return NULL;
}
/* check_code() parse 'code' and return NULL or an error response * string. If we return NULL then real_code contains code converted * to the cnnnn format.
*/ staticchar *check_code(apr_pool_t *p, constchar *code, char **real_code)
{ char *word; char base = 'X'; int modifier = 0; int num = 0; int factor;
staticconst command_rec expires_cmds[] =
{
AP_INIT_FLAG("ExpiresActive", set_expiresactive, 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, "an expiry date code"),
{NULL}
};
switch (code[0]) { case'M': if (r->finfo.filetype == APR_NOFILE) { /* file doesn't exist on disk, so we can't do anything based on * modification time. Note that this does _not_ log an error.
*/ return DECLINED;
}
base = r->finfo.mtime;
additional_sec = atoi(&code[1]);
additional = apr_time_from_sec(additional_sec); break; case'A': /* there's been some discussion and it's possible that * 'access time' will be stored in request structure
*/
base = r->request_time;
additional_sec = atoi(&code[1]);
additional = apr_time_from_sec(additional_sec); break; default: /* expecting the add_* routines to be case-hardened this * is just a reminder that module is beta
*/
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01500) "internal error: bad expires code: %s", r->filename); return HTTP_INTERNAL_SERVER_ERROR;
}
/* * Output filter to set the Expires response header field * according to the content-type of the response -- if it hasn't * already been set.
*/ static apr_status_t expires_filter(ap_filter_t *f,
apr_bucket_brigade *b)
{
request_rec *r;
expires_dir_config *conf; constchar *expiry;
apr_table_t *t;
/* Don't add Expires headers to errors */ if (ap_is_HTTP_ERROR(f->r->status)) {
ap_remove_output_filter(f); return ap_pass_brigade(f->next, b);
}
r = f->r;
conf = (expires_dir_config *) ap_get_module_config(r->per_dir_config,
&expires_module);
/* * Check to see which output header table we should use; * mod_cgi loads script fields into r->err_headers_out, * for instance.
*/
expiry = apr_table_get(r->err_headers_out, "Expires"); if (expiry != NULL) {
t = r->err_headers_out;
} else {
expiry = apr_table_get(r->headers_out, "Expires");
t = r->headers_out;
} if (expiry == NULL) { /* * No expiration has been set, so we can apply any managed by * this module. First, check to see if there is an applicable * ExpiresByType directive.
*/
expiry = apr_table_get(conf->expiresbytype,
ap_field_noparam(r->pool, r->content_type)); if (expiry == NULL) { int usedefault = 1; /* * See if we have a wildcard entry for the major type.
*/ if (conf->wildcards) { char *checkmime; char *spos;
checkmime = apr_pstrdup(r->pool, r->content_type);
spos = checkmime ? ap_strchr(checkmime, '/') : NULL; if (spos != NULL) { /* * Without a '/' character, nothing we have will match. * However, we have one.
*/ if (strlen(++spos) > 0) {
*spos++ = '*';
*spos = '\0';
} else {
checkmime = apr_pstrcat(r->pool, checkmime, "*", NULL);
}
expiry = apr_table_get(conf->expiresbytype, checkmime);
usedefault = (expiry == NULL);
}
} if (usedefault) { /* * Use the ExpiresDefault directive
*/
expiry = conf->expiresdefault;
}
} if (expiry != NULL) {
set_expiration_fields(r, expiry, t);
}
}
ap_remove_output_filter(f); return ap_pass_brigade(f->next, b);
}
/* Don't add Expires headers to errors */ if (ap_is_HTTP_ERROR(r->status)) { return;
} /* Say no to subrequests */ if (r->main != NULL) { return;
}
conf = (expires_dir_config *) ap_get_module_config(r->per_dir_config,
&expires_module);
/* Check to see if the filter is enabled and if there are any applicable * config directives for this directory scope
*/ if (conf->active != ACTIVE_ON ||
(apr_is_empty_table(conf->expiresbytype) && !conf->expiresdefault)) { return;
}
ap_add_output_filter("MOD_EXPIRES", NULL, r, r->connection);
}
staticvoid register_hooks(apr_pool_t *p)
{ /* mod_expires needs to run *before* the cache save filter which is * AP_FTYPE_CONTENT_SET-1. Otherwise, our expires won't be honored.
*/
ap_register_output_filter("MOD_EXPIRES", expires_filter, NULL,
AP_FTYPE_CONTENT_SET-2);
ap_hook_insert_error_filter(expires_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_insert_filter(expires_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
}
AP_DECLARE_MODULE(expires) =
{
STANDARD20_MODULE_STUFF,
create_dir_expires_config, /* dir config creater */
merge_expires_dir_configs, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server configs */
expires_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};
¤ Dauer der Verarbeitung: 0.21 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.