cache_storage.c revision 66c863abfe28fd753dba68c025f32ff768640387
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Copyright 2001-2005 The Apache Software Foundation or its licensors, as
199767f8919635c4928607450d9e0abb932109ceToomas Soome * applicable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Licensed under the Apache License, Version 2.0 (the "License");
199767f8919635c4928607450d9e0abb932109ceToomas Soome * you may not use this file except in compliance with the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You may obtain a copy of the License at
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * http://www.apache.org/licenses/LICENSE-2.0
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Unless required by applicable law or agreed to in writing, software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * distributed under the License is distributed on an "AS IS" BASIS,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * See the License for the specific language governing permissions and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * limitations under the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define CORE_PRIVATE
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "mod_cache.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern APR_OPTIONAL_FN_TYPE(ap_cache_generate_key) *cache_generate_key;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern module AP_MODULE_DECLARE_DATA cache_module;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* -------------------------------------------------------------- */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * delete all URL entities from the cache
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint cache_remove_url(request_rec *r, char *url)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache_provider_list *list;
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_status_t rv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *key;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache_request_rec *cache = (cache_request_rec *)
199767f8919635c4928607450d9e0abb932109ceToomas Soome ap_get_module_config(r->request_config, &cache_module);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome rv = cache_generate_key(r,r->pool,&key);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (rv != APR_SUCCESS) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return rv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome list = cache->providers;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* for each specified cache type, delete the URL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome while(list) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome list->provider->remove_url(key);
199767f8919635c4928607450d9e0abb932109ceToomas Soome list = list->next;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return OK;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * create a new URL entity in the cache
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * It is possible to store more than once entity per URL. This
199767f8919635c4928607450d9e0abb932109ceToomas Soome * function will always create a new entity, regardless of whether
199767f8919635c4928607450d9e0abb932109ceToomas Soome * other entities already exist for the same URL.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The size of the entity is provided so that a cache module can
199767f8919635c4928607450d9e0abb932109ceToomas Soome * decide whether or not it wants to cache this particular entity.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If the size is unknown, a size of -1 should be set.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint cache_create_entity(request_rec *r, char *url, apr_off_t size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache_provider_list *list;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache_handle_t *h = apr_pcalloc(r->pool, sizeof(cache_handle_t));
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *key;
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_status_t rv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache_request_rec *cache = (cache_request_rec *)
199767f8919635c4928607450d9e0abb932109ceToomas Soome ap_get_module_config(r->request_config, &cache_module);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome rv = cache_generate_key(r, r->pool, &key);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (rv != APR_SUCCESS) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return rv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome list = cache->providers;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* for each specified cache type, delete the URL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (list) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (rv = list->provider->create_entity(h, r, key, size)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case OK: {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache->handle = h;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache->provider = list->provider;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache->provider_name = list->provider_name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome return OK;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome case DECLINED: {
199767f8919635c4928607450d9e0abb932109ceToomas Soome list = list->next;
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome default: {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return rv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return DECLINED;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int set_cookie_doo_doo(void *v, const char *key, const char *val)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_addn(v, key, val);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCACHE_DECLARE(void) ap_cache_accept_headers(cache_handle_t *h, request_rec *r,
199767f8919635c4928607450d9e0abb932109ceToomas Soome int preserve_orig)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_t *cookie_table, *hdr_copy;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *v;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome v = apr_table_get(h->resp_hdrs, "Content-Type");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (v) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome ap_set_content_type(r, v);
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_unset(h->resp_hdrs, "Content-Type");
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* If the cache gave us a Last-Modified header, we can't just
199767f8919635c4928607450d9e0abb932109ceToomas Soome * pass it on blindly because of restrictions on future values.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome v = apr_table_get(h->resp_hdrs, "Last-Modified");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (v) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome ap_update_mtime(r, apr_date_parse_http(v));
199767f8919635c4928607450d9e0abb932109ceToomas Soome ap_set_last_modified(r);
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_unset(h->resp_hdrs, "Last-Modified");
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* The HTTP specification says that it is legal to merge duplicate
199767f8919635c4928607450d9e0abb932109ceToomas Soome * headers into one. Some browsers that support Cookies don't like
199767f8919635c4928607450d9e0abb932109ceToomas Soome * merged headers and prefer that each Set-Cookie header is sent
199767f8919635c4928607450d9e0abb932109ceToomas Soome * separately. Lets humour those browsers by not merging.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Oh what a pain it is.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome cookie_table = apr_table_make(r->pool, 2);
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_do(set_cookie_doo_doo, cookie_table, r->err_headers_out,
199767f8919635c4928607450d9e0abb932109ceToomas Soome "Set-Cookie", NULL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_do(set_cookie_doo_doo, cookie_table, h->resp_hdrs,
199767f8919635c4928607450d9e0abb932109ceToomas Soome "Set-Cookie", NULL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_unset(r->err_headers_out, "Set-Cookie");
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_unset(h->resp_hdrs, "Set-Cookie");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (preserve_orig) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome hdr_copy = apr_table_copy(r->pool, h->resp_hdrs);
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_overlap(hdr_copy, r->headers_out, APR_OVERLAP_TABLES_SET);
199767f8919635c4928607450d9e0abb932109ceToomas Soome r->headers_out = hdr_copy;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_overlap(r->headers_out, h->resp_hdrs, APR_OVERLAP_TABLES_SET);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!apr_is_empty_table(cookie_table)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome r->err_headers_out = apr_table_overlay(r->pool, r->err_headers_out,
199767f8919635c4928607450d9e0abb932109ceToomas Soome cookie_table);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * select a specific URL entity in the cache
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * It is possible to store more than one entity per URL. Content
199767f8919635c4928607450d9e0abb932109ceToomas Soome * negotiation is used to select an entity. Once an entity is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * selected, details of it are stored in the per request
199767f8919635c4928607450d9e0abb932109ceToomas Soome * config to save time when serving the request later.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This function returns OK if successful, DECLINED if no
199767f8919635c4928607450d9e0abb932109ceToomas Soome * cached entity fits the bill.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint cache_select_url(request_rec *r, char *url)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache_provider_list *list;
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_status_t rv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache_handle_t *h;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *key;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache_request_rec *cache = (cache_request_rec *)
199767f8919635c4928607450d9e0abb932109ceToomas Soome ap_get_module_config(r->request_config, &cache_module);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome rv = cache_generate_key(r, r->pool, &key);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (rv != APR_SUCCESS) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return rv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* go through the cache types till we get a match */
199767f8919635c4928607450d9e0abb932109ceToomas Soome h = apr_palloc(r->pool, sizeof(cache_handle_t));
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome list = cache->providers;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (list) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch ((rv = list->provider->open_entity(h, r, key))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case OK: {
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *vary = NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int fresh;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (list->provider->recall_headers(h, r) != APR_SUCCESS) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* TODO: Handle this error */
199767f8919635c4928607450d9e0abb932109ceToomas Soome return DECLINED;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Check Content-Negotiation - Vary
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * At this point we need to make sure that the object we found in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the cache is the same object that would be delivered to the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * client, when the effects of content negotiation are taken into
199767f8919635c4928607450d9e0abb932109ceToomas Soome * effect.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * In plain english, we want to make sure that a language-negotiated
199767f8919635c4928607450d9e0abb932109ceToomas Soome * document in one language is not given to a client asking for a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * language negotiated document in a different language by mistake.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This code makes the assumption that the storage manager will
199767f8919635c4928607450d9e0abb932109ceToomas Soome * cache the req_hdrs if the response contains a Vary
199767f8919635c4928607450d9e0abb932109ceToomas Soome * header.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * RFC2616 13.6 and 14.44 describe the Vary mechanism.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome vary = apr_pstrdup(r->pool, apr_table_get(h->resp_hdrs, "Vary"));
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (vary && *vary) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *name = vary;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *h1, *h2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* isolate header name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (*vary && !apr_isspace(*vary) && (*vary != ','))
199767f8919635c4928607450d9e0abb932109ceToomas Soome ++vary;
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (*vary && (apr_isspace(*vary) || (*vary == ','))) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome *vary = '\0';
199767f8919635c4928607450d9e0abb932109ceToomas Soome ++vary;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is this header in the request and the header in the cached
199767f8919635c4928607450d9e0abb932109ceToomas Soome * request identical? If not, we give up and do a straight get
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome h1 = apr_table_get(r->headers_in, name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome h2 = apr_table_get(h->req_hdrs, name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (h1 == h2) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* both headers NULL, so a match - do nothing */
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (h1 && h2 && !strcmp(h1, h2)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* both headers exist and are equal - do nothing */
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* headers do not match, so Vary failed */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS,
199767f8919635c4928607450d9e0abb932109ceToomas Soome r->server,
199767f8919635c4928607450d9e0abb932109ceToomas Soome "cache_select_url(): Vary header mismatch.");
199767f8919635c4928607450d9e0abb932109ceToomas Soome return DECLINED;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache->provider = list->provider;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache->provider_name = list->provider_name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Is our cached response fresh enough? */
199767f8919635c4928607450d9e0abb932109ceToomas Soome fresh = ap_cache_check_freshness(h, r);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!fresh) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *etag, *lastmod;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Make response into a conditional */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* FIXME: What if the request is already conditional? */
199767f8919635c4928607450d9e0abb932109ceToomas Soome etag = apr_table_get(h->resp_hdrs, "ETag");
199767f8919635c4928607450d9e0abb932109ceToomas Soome lastmod = apr_table_get(h->resp_hdrs, "Last-Modified");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (etag || lastmod) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* If we have a cached etag and/or Last-Modified */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache->stale_headers = apr_table_copy(r->pool,
199767f8919635c4928607450d9e0abb932109ceToomas Soome r->headers_in);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (etag) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_set(r->headers_in, "If-None-Match", etag);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (lastmod) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome apr_table_set(r->headers_in, "If-Modified-Since",
199767f8919635c4928607450d9e0abb932109ceToomas Soome lastmod);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache->stale_handle = h;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return DECLINED;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Okay, this response looks okay. Merge in our stuff and go. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ap_cache_accept_headers(h, r, 0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome cache->handle = h;
199767f8919635c4928607450d9e0abb932109ceToomas Soome return OK;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome case DECLINED: {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* try again with next cache type */
199767f8919635c4928607450d9e0abb932109ceToomas Soome list = list->next;
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome default: {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* oo-er! an error */
199767f8919635c4928607450d9e0abb932109ceToomas Soome return rv;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return DECLINED;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeapr_status_t cache_generate_key_default(request_rec *r, apr_pool_t* p,
199767f8919635c4928607450d9e0abb932109ceToomas Soome char**key)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (r->hostname) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome *key = apr_pstrcat(p, r->hostname, r->uri, "?", r->args, NULL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome *key = apr_pstrcat(p, r->uri, "?", r->args, NULL);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return APR_SUCCESS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome