mod_expires.c revision ba09062ce0c7e0d6904a53aaf99896f5924b3989
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/* ====================================================================
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * The Apache Software License, Version 1.1
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Copyright (c) 2000 The Apache Software Foundation. All rights
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Redistribution and use in source and binary forms, with or without
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * modification, are permitted provided that the following conditions
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * 1. Redistributions of source code must retain the above copyright
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * notice, this list of conditions and the following disclaimer.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * 2. Redistributions in binary form must reproduce the above copyright
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * notice, this list of conditions and the following disclaimer in
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * the documentation and/or other materials provided with the
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * distribution.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * 3. The end-user documentation included with the redistribution,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * if any, must include the following acknowledgment:
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * "This product includes software developed by the
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Apache Software Foundation (http://www.apache.org/)."
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Alternately, this acknowledgment may appear in the software itself,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * if and wherever such third-party acknowledgments normally appear.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * 4. The names "Apache" and "Apache Software Foundation" must
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering * not be used to endorse or promote products derived from this
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * software without prior written permission. For written
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * permission, please contact apache@apache.org.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * 5. Products derived from this software may not be called "Apache",
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * nor may "Apache" appear in their name, without prior written
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * permission of the Apache Software Foundation.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * SUCH DAMAGE.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * ====================================================================
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * This software consists of voluntary contributions made by many
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * individuals on behalf of the Apache Software Foundation. For more
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * information on the Apache Software Foundation, please see
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * Portions of this software are based upon public domain software
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * originally written at the National Center for Supercomputing Applications,
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * University of Illinois, Urbana-Champaign.
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * version 0.0.11
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * status beta
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Andrew Wilson <Andrew.Wilson@cm.cf.ac.uk> 26.Jan.96
b9e7a9d870ac41d4db954edd52a1f5dd7d153389Lennart Poettering * This module allows you to control the form of the Expires: header
b9e7a9d870ac41d4db954edd52a1f5dd7d153389Lennart Poettering * that Apache issues for each access. Directives can appear in
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * configuration files or in .htaccess files so expiry semantics can
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * be defined on a per-directory basis.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * DIRECTIVE SYNTAX
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Valid directives are:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ExpiresActive on | off
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * ExpiresDefault <code><seconds>
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * ExpiresByType type/encoding <code><seconds>
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * Valid values for <code> are:
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * 'M' expires header shows file modification date + <seconds>
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * 'A' expires header shows access time + <seconds>
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * [I'm not sure which of these is best under different
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * circumstances, I guess it's for other people to explore.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * The effects may be indistinguishable for a number of cases]
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * <seconds> should be an integer value [acceptable to atoi()]
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * There is NO space between the <code> and <seconds>.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * For example, a directory which contains information which changes
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * frequently might contain:
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * # reports generated by cron every hour. don't let caches
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * # hold onto stale information
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ExpiresDefault M3600
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Another example, our html pages can change all the time, the gifs
96e6e394431dcc1db52847be311e2c8e61d7a9d6Lennart Poettering * tend not to change often:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * # pages are hot (1 week), images are cold (1 month)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ExpiresByType text/html A604800
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * ExpiresByType image/gif A2592000
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Expires can be turned on for all URLs on the server by placing the
* of the mod_cern_meta.c functionality. eg:
* ExpiresExplicit index.html "modification plus 30 days"
#include "ap_config.h"
#ifdef HAVE_CTYPE_H
#include <ctype.h>
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_request.h"
#include "apr_strings.h"
int active;
char *expiresdefault;
#define ACTIVE_OFF 0
return (void *) new;
if (arg == 0) {
return NULL;
char *word;
int modifier = 0;
int num = 0;
int factor = 0;
return NULL;
while (word[0]) {
if (word[0]) {
factor = 0;
return NULL;
return NULL;
const char *code)
return NULL;
{NULL}
return new;
char *code;
char *timestr;
return DECLINED;
return DECLINED;
return HTTP_INTERNAL_SERVER_ERROR;
return DECLINED;
return OK;
switch (code[0]) {
return DECLINED;
return HTTP_INTERNAL_SERVER_ERROR;
/ APR_USEC_PER_SEC));
return OK;
static void register_hooks(void)