View | Details | Raw Unified | Return to bug 43826
Collapse All | Expand All

(-)modules/cache/mod_cache.c (-21 / +58 lines)
Lines 44-65 Link Here
44
 *     add CACHE_SAVE filter
44
 *     add CACHE_SAVE filter
45
 *   If No:
45
 *   If No:
46
 *     oh well.
46
 *     oh well.
47
 * Does this request invalidate our Cache? (PUT|POST|DELETE)
48
 *  attach cache_remove_url_filter and exit.
47
 */
49
 */
48
50
49
static int cache_url_handler(request_rec *r, int lookup)
51
static int cache_url_handler(request_rec *r, int lookup)
50
{
52
{
51
    apr_status_t rv;
53
    apr_status_t rv;
52
    const char *auth;
53
    cache_provider_list *providers;
54
    cache_provider_list *providers;
54
    cache_request_rec *cache;
55
    cache_request_rec *cache;
55
    cache_server_conf *conf;
56
    cache_server_conf *conf;
56
    apr_bucket_brigade *out;
57
    apr_bucket_brigade *out;
57
    ap_filter_t *next;
58
    ap_filter_t *next;
58
    ap_filter_rec_t *cache_out_handle;
59
    ap_filter_rec_t *cache_out_handle;
60
    int remove_due_to_method = 0;
59
61
60
    /* Delay initialization until we know we are handling a GET */
62
    switch (r->method_number) {
61
    if (r->method_number != M_GET) {
63
        case M_POST:
62
        return DECLINED;
64
        case M_PUT:
65
        case M_DELETE:
66
            /* If remove_due_to_method is set we have a POST, DELETE or PUT
67
             * request on the resource which according to RFC2616 13.1 causes
68
             * a possible existing cached resource to be invalided and
69
             * ejected from the cache. It is perfectly possible that POST, DELETE or
70
             * PUT on this resource is protected while a GET on this resource that
71
             * caused the resource to be cached is not. So we need not check for
72
             * auth here.
73
             * If remove_due_to_method is set it is guaranteed anyway that we DECLINE
74
             * later, but we need to have cache_select run before to be able to
75
             * eject the cached resource from the cache.
76
             */
77
            remove_due_to_method = 1;
78
            break;
79
        case M_GET:
80
            /* Are we allowed to serve cached info at all? Check Auth headers
81
             * and get out if we they are set.
82
             */
83
            if(!apr_table_get(r->headers_in, "Authorization"))
84
                break;
85
        default:
86
            return DECLINED;
63
    }
87
    }
64
88
65
    conf = (cache_server_conf *) ap_get_module_config(r->server->module_config,
89
    conf = (cache_server_conf *) ap_get_module_config(r->server->module_config,
Lines 84-104 Link Here
84
    cache->providers = providers;
108
    cache->providers = providers;
85
109
86
    /*
110
    /*
87
     * Are we allowed to serve cached info at all?
111
     * Try to select and serve this request from the cache.
88
     */
112
     * If it is an invalidating method, add the remove_url_filter and exit
89
90
    /* find certain cache controlling headers */
91
    auth = apr_table_get(r->headers_in, "Authorization");
92
93
    /* First things first - does the request allow us to return
94
     * cached information at all? If not, just decline the request.
95
     */
96
    if (auth) {
97
        return DECLINED;
98
    }
99
100
    /*
101
     * Try to serve this request from the cache.
102
     *
113
     *
103
     * If no existing cache file (DECLINED)
114
     * If no existing cache file (DECLINED)
104
     *   add cache_save filter
115
     *   add cache_save filter
Lines 108-113 Link Here
108
     *   return OK
119
     *   return OK
109
     */
120
     */
110
    rv = cache_select(r);
121
    rv = cache_select(r);
122
    /*
123
     * Eject a possible cached resource from cache if handle a POST, DELETE or PUT
124
     * on this resource.
125
     * Note: cache_remove_url can handle the case when no cached resource
126
     * was found by cache_select.
127
     */
128
    if (remove_due_to_method) {
129
        cache->remove_url_filter =
130
            ap_add_output_filter_handle(cache_remove_url_filter_handle,
131
                    cache, r, r->connection);
132
        return DECLINED;
133
    }
111
    if (rv != OK) {
134
    if (rv != OK) {
112
        if (rv == DECLINED) {
135
        if (rv == DECLINED) {
113
            if (!lookup) {
136
            if (!lookup) {
Lines 884-892 Link Here
884
        ap_remove_output_filter(f);
907
        ap_remove_output_filter(f);
885
        return ap_pass_brigade(f->next, in);
908
        return ap_pass_brigade(f->next, in);
886
    }
909
    }
887
    /* Now remove this cache entry from the cache */
888
    cache_remove_url(cache, r->pool);
889
910
911
    switch(r->method_number) {
912
        case M_POST:
913
        case M_PUT:
914
        case M_DELETE:
915
            /* If it was invalid in some way, cache does not want to notice it.
916
             * This is not specified in RFC, but it is slightly nicer
917
             * and protects against accidental cache evicion. (A user can still force
918
             * it with GET | [Cache-control: max-age=0] )
919
             */
920
            if (r->status > 400) break;
921
        case M_GET:
922
            /* Nothing to check remove it from cache.*/
923
            cache_remove_url(cache, r->pool);
924
        default:
925
            break;
926
    }
890
    /* remove ourselves */
927
    /* remove ourselves */
891
    ap_remove_output_filter(f);
928
    ap_remove_output_filter(f);
892
    return ap_pass_brigade(f->next, in);
929
    return ap_pass_brigade(f->next, in);

Return to bug 43826