MCPcopy Create free account
hub / github.com/apache/httpd / file_cache_handler

Function file_cache_handler

modules/cache/mod_file_cache.c:307–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307static int file_cache_handler(request_rec *r)
308{
309 a_file *match;
310 int errstatus;
311 int rc = OK;
312
313 /* Bail out if r->handler isn't the default value, and doesn't look like a Content-Type
314 * XXX: Even though we made the user explicitly list each path to cache?
315 */
316 if (ap_strcmp_match(r->handler, "*/*") && !AP_IS_DEFAULT_HANDLER_NAME(r->handler)) {
317 return DECLINED;
318 }
319
320 /* we don't handle anything but GET */
321 if (r->method_number != M_GET) return DECLINED;
322
323 /* did xlat phase find the file? */
324 match = ap_get_module_config(r->request_config, &file_cache_module);
325
326 if (match == NULL) {
327 return DECLINED;
328 }
329
330 /* note that we would handle GET on this resource */
331 r->allowed |= (AP_METHOD_BIT << M_GET);
332
333 /* This handler has no use for a request body (yet), but we still
334 * need to read and discard it if the client sent one.
335 */
336 if ((errstatus = ap_discard_request_body(r)) != OK)
337 return errstatus;
338
339 ap_update_mtime(r, match->finfo.mtime);
340
341 /* ap_set_last_modified() always converts the file mtime to a string
342 * which is slow. Accelerate the common case.
343 * ap_set_last_modified(r);
344 */
345 {
346 apr_time_t mod_time;
347 char *datestr;
348
349 mod_time = ap_rationalize_mtime(r, r->mtime);
350 if (mod_time == match->finfo.mtime)
351 datestr = match->mtimestr;
352 else {
353 datestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
354 apr_rfc822_date(datestr, mod_time);
355 }
356 apr_table_setn(r->headers_out, "Last-Modified", datestr);
357 }
358
359 /* ap_set_content_length() always converts the same number and never
360 * returns an error. Accelerate it.
361 */
362 r->clength = match->finfo.size;
363 apr_table_setn(r->headers_out, "Content-Length", match->sizestr);
364

Callers

nothing calls this directly

Calls 9

ap_strcmp_matchFunction · 0.85
ap_get_module_configFunction · 0.85
ap_discard_request_bodyFunction · 0.85
ap_update_mtimeFunction · 0.85
ap_rationalize_mtimeFunction · 0.85
ap_set_etagFunction · 0.85
ap_meets_conditionsFunction · 0.85
mmap_handlerFunction · 0.85
sendfile_handlerFunction · 0.85

Tested by

no test coverage detected