* Hook and mod_cache callback functions */
| 355 | * Hook and mod_cache callback functions |
| 356 | */ |
| 357 | static int create_entity(cache_handle_t *h, request_rec *r, const char *key, |
| 358 | apr_off_t len, apr_bucket_brigade *bb) |
| 359 | { |
| 360 | cache_socache_dir_conf *dconf = |
| 361 | ap_get_module_config(r->per_dir_config, &cache_socache_module); |
| 362 | cache_socache_conf *conf = ap_get_module_config(r->server->module_config, |
| 363 | &cache_socache_module); |
| 364 | cache_object_t *obj; |
| 365 | cache_socache_object_t *sobj; |
| 366 | apr_size_t total; |
| 367 | |
| 368 | if (conf->provider == NULL) { |
| 369 | return DECLINED; |
| 370 | } |
| 371 | |
| 372 | /* we don't support caching of range requests (yet) */ |
| 373 | /* TODO: but we could */ |
| 374 | if (r->status == HTTP_PARTIAL_CONTENT) { |
| 375 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02345) |
| 376 | "URL %s partial content response not cached", |
| 377 | key); |
| 378 | return DECLINED; |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * We have a chicken and egg problem. We don't know until we |
| 383 | * attempt to store_headers just how big the response will be |
| 384 | * and whether it will fit in the cache limits set. But we |
| 385 | * need to make a decision now as to whether we plan to try. |
| 386 | * If we make the wrong decision, we could prevent another |
| 387 | * cache implementation, such as cache_disk, from getting the |
| 388 | * opportunity to cache, and that would be unfortunate. |
| 389 | * |
| 390 | * In a series of tests, from cheapest to most expensive, |
| 391 | * decide whether or not to ignore this attempt to cache, |
| 392 | * with a small margin just to be sure. |
| 393 | */ |
| 394 | if (len < 0) { |
| 395 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02346) |
| 396 | "URL '%s' had no explicit size, ignoring", key); |
| 397 | return DECLINED; |
| 398 | } |
| 399 | if (len > dconf->max) { |
| 400 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02347) |
| 401 | "URL '%s' body larger than limit, ignoring " |
| 402 | "(%" APR_OFF_T_FMT " > %" APR_OFF_T_FMT ")", |
| 403 | key, len, dconf->max); |
| 404 | return DECLINED; |
| 405 | } |
| 406 | |
| 407 | /* estimate the total cached size, given current headers */ |
| 408 | total = len + sizeof(cache_socache_info_t) + strlen(key); |
| 409 | if (APR_SUCCESS != store_table(r->headers_out, NULL, dconf->max, &total) |
| 410 | || APR_SUCCESS != store_table(r->headers_in, NULL, dconf->max, |
| 411 | &total)) { |
| 412 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02348) |
| 413 | "URL '%s' estimated headers size larger than limit, ignoring " |
| 414 | "(%" APR_SIZE_T_FMT " > %" APR_OFF_T_FMT ")", |
nothing calls this directly
no test coverage detected