Commit ae1bc2e5 authored by Sander Striker's avatar Sander Striker
Browse files

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
parent 8bca01cd
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -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);
                    }
+13 −10
Original line number Diff line number Diff line
@@ -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);