From: Sander Striker Date: Sun, 6 Mar 2005 18:57:22 +0000 (+0000) Subject: More mod_cache tweakage... X-Git-Tag: 2.1.4~21 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c70cb4ba14274d4e7e6b1424f7599651dfe62ebd;p=apache More mod_cache tweakage... * modules/cache/mod_cache.c (cache_save_filter): Instead of unconditionally returning a 304 when the original request was conditional and we issued a cache revalidating request, handle the request as if it came in while our cache was still valid. * modules/cache/cache_storage.c (cache_select_url): Strip off the conditional headers from the original request, prior to adding our own for the purpose of revalidating our cached response. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@156330 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/cache/cache_storage.c b/modules/cache/cache_storage.c index b3489803c4..1aaf328253 100644 --- a/modules/cache/cache_storage.c +++ b/modules/cache/cache_storage.c @@ -256,16 +256,26 @@ int cache_select_url(request_rec *r, char *url) const char *etag, *lastmod; /* Make response into a conditional */ + cache->stale_headers = apr_table_copy(r->pool, + r->headers_in); + + /* We can only revalidate with our own conditionals: remove the + * conditions from the original request. + */ + apr_table_unset(r->headers_in, "If-Match"); + apr_table_unset(r->headers_in, "If-Modified-Since"); + apr_table_unset(r->headers_in, "If-None-Match"); + apr_table_unset(r->headers_in, "If-Range"); + apr_table_unset(r->headers_in, "If-Unmodified-Since"); - /* FIXME: What if the request is already conditional? */ etag = apr_table_get(h->resp_hdrs, "ETag"); lastmod = apr_table_get(h->resp_hdrs, "Last-Modified"); if (etag || lastmod) { - /* If we have a cached etag and/or Last-Modified */ + /* If we have a cached etag and/or Last-Modified add in + * our own conditionals. + */ - cache->stale_headers = apr_table_copy(r->pool, - r->headers_in); if (etag) { apr_table_set(r->headers_in, "If-None-Match", etag); } diff --git a/modules/cache/mod_cache.c b/modules/cache/mod_cache.c index ecc196f9cf..282447d424 100644 --- a/modules/cache/mod_cache.c +++ b/modules/cache/mod_cache.c @@ -688,22 +688,25 @@ static int cache_save_filter(ap_filter_t *f, apr_bucket_brigade *in) /* Did we just update the cached headers on a revalidated response? * - * If so, we can now decide what to serve to the client: - * - If the original request was conditional and is satisified, send 304. - * - Otherwise, send the cached body. - */ + * If so, we can now decide what to serve to the client. This is done in + * the same way as with a regular response, but conditions are now checked + * against the cached or merged response headers. + */ if (rv == APR_SUCCESS && cache->stale_handle) { apr_bucket_brigade *bb; apr_bucket *bkt; + int status; bb = apr_brigade_create(r->pool, r->connection->bucket_alloc); - /* Were we initially a conditional request? */ - if (ap_cache_request_is_conditional(cache->stale_headers)) { - /* FIXME: We must ensure that the request meets conditions. */ - - /* Set the status to be a 304. */ - r->status = HTTP_NOT_MODIFIED; + /* Restore the original request headers and see if we need to + * return anything else than the cached response (ie. the original + * request was conditional). + */ + r->headers_in = cache->stale_headers; + status = ap_meets_conditions(r); + if (status != OK) { + r->status = status; bkt = apr_bucket_flush_create(bb->bucket_alloc); APR_BRIGADE_INSERT_TAIL(bb, bkt);